My Product model has the following relationship:
public function categoria(){
return $this->belongsTo('estoque\Categoria');
}
and my model Category has:
public function produtos(){
return $this->hasMany('estoque\Produto');
}
When trying to access in view
:
<td> {{$p->categoria}} <td>
Return me:
{"id":1,"nome":"Cerveja","descricao":"Todas cervejas","ativo":1,"created_at":"2015-10-24 13:53:14","updated_at":"2015-10-24 13:53:14"}
But I need only the category name, so I'm trying to access it like this:
<td> {{$p->categoria->nome}} <td>
But it generates the following error:
Trying to get property of non-object
According to the documentation on the Lavael site, I could use {{$p->categoria->nome}}
, but I can not. Any ideas?