Şöyle yapmaya karar verdim
//Model
class ProductCategory extends Eloquent {
protected $table = 'product_categories';
protected $softDelete = true;
protected $guarded = array();
public function products()
{
return $this->belongsToMany('Product','product_category_relations')->where('is_home','=',1)->take(10);
}
//controller
$categories = \ProductCategory::whereIsHome(1)->get();
//blade
@foreach($categories as $category)
@foreach($category->products as $product)
{{ $product->name }}
@endforeach
@endforeach
yukarıda yapmış olduğum kodlar ile bunu sağlaya bildim ama ben biraz daha öteye taşıyarak
"where cumlemdaki whereIsHome veya take kısmını" bir parametre yardımı ile değiştirmekte istiyordum ve yukarıyı şuna cevirdim.
//model
public function products($where,$take)
{
return $this->belongsToMany('Product','product_category_relations')->where($where,'=',1)->take($take);
}
//blade
@foreach($categories as $category)
@foreach($category->products('is_home',5) as $product)
{{ $product->name }}
@endforeach
@endforeach
fakat bu sefer hiçbir veri döndermedi ama hatada vermedi.
Not : is_home = 1 olan veri var