1
I am beginner with the Laravel need to return the name of the client in the View orders, at the moment is only getting the ID
Classes
class Ordem extends Model
{
protected $fillable =['id','cliente_id','valor','data','problema',];
public function produtos()
{
return $this->belongsToMany(produto::class, 'ordem_id');
}
public function servicos()
{
return $this->belongsToMany(servico::class,'ordem_id');
}
}
class Cliente extends Model
{
protected $fillable = ['id','nome','cpf','endereco','telefone','email'];
protected $table = 'clientes';
public function ordens()
{
return $this->hasMany(ordem::class,'cliente_id');
}
}
class OrdemController extends Controller
{
public function listaordens()
{
$list_ordens = Ordem::all();
return view('ordem.listaordens',['ordens' => $list_ordens]);
}
}
View
@foreach($ordens as $o)
<tr>
<td> {{$o->cliente_id}} </td>
<td class="text-right"> {{($o->data)}} </td>
<td class="text-center"> {{$o->problema}} </td>
<td class="text-right"> {{$o->valor}} </td>
<td class="text-center">
Roni, do the Tour, vote for the answers that help you and the community.
– novic