I have three models:
class Brand extends \Eloquent {
protected $fillable = [];
public function product()
{
return $this->hasMany('Product');
}
}
class Product extends \Eloquent {
protected $fillable = [];
public function reviews()
{
return $this->hasMany('Review');
}
public function brand()
{
return $this->belongsTo('Brand');
}
}
class Review extends \Eloquent {
protected $fillable = [];
public function product()
{
return $this->belongsTo('Product');
}
}
I'm trying to display brand names along with product and review counts in a view:
{{ $brand->product->count() }}
it works for this, but doesn't display reviews count:
{{ $brand->product->reviews->count() }}
neither for:
{{ $brand->product->reviews->count() }}
Errors I'm getting are:
ErrorException (E_UNKNOWN)
Undefined property: Illuminate\Database\Eloquent\Collection::$review
ErrorException (E_UNKNOWN)
Undefined property: Illuminate\Database\Eloquent\Collection::$reviews