I have two tables, produtos
and categorias
.
In my view
of produtos
I want to show the category name of that product, not your code.
Category Template Category.php
namespace MagicCommerce\Site\Cadastros;
class Categoria extends \Eloquent {
public function produtos() {
return $this->hasMany('Produto');
}
}
Product Template Product.php
namespace MagicCommerce\Site\Cadastros;
class Produto extends \Eloquent {
public function categoria() {
return $this->belongsTo('Categoria');
}
}
And in my view
I try to call the relationship using:
@foreach ($produtos as $p)
{{ $p->categoria->nome }}
@endforeach
And the following is returned to me:
Symfony \ Component \ Debug \ Exception \ FatalErrorException Class 'Category' not found
Access the base data normally, only the relationship does not work. I've also circled dump-autoload
, but no success.