mgsmus hocam;
kategori sayfamda ürünleri çekmek için $category->getProducts şeklinde modelden çağırıyorum.
getProducts metodu içerisi şu şekilde;
`public function getProducts($id = null)
{
if($id==null){ $pass_id = $this->id; }else{ $pass_id = $id; } // kategoride ki benzer ürünler için oluşturuldu
$result = DB::table('product_category_pivot')
->where(['product_category_pivot.category_id' => $pass_id, 'product_variation.show_primary' => 1, 'product.deleted_at' => null, 'product.publish' => 0])
->join('product','product.id','=','product_category_pivot.product_id')
->join('product_variation','product_variation.product_id','=','product_category_pivot.product_id')
->join('product_options_pivot','product_options_pivot.product_id','=','product_category_pivot.product_id') ## varyasyon filtre için sonradan ekledim
->select(
'product.*',
'product_variation.id as pro_var_id','product_variation.title as pro_var_title','product_variation.slug as pro_var_slug',
'product_variation.sku as pro_var_sku','product_variation.price as pro_var_price','product_variation.stock as pro_var_stock'
)
->groupBy('product_variation.id')
->orderBy('product.id','desc');
$request_arr = request()->except("filtre");
if( isset($request_arr["marka"]) ) {
$result->join('brand_pivot', function ($join) {
$join->on('brand_pivot.product_id', '=', 'product.id')->where('brand_pivot.brand_id', '=', strip_tags($request_arr["marka"]));
});
unset($request_arr["marka"]);
}
unset($request_arr["fiyat"]);
$filters = [];
foreach ($request_arr as $key => $value) {
if(strpos($value, '|') !== false) {
$filter = explode('|', $value);
$filters[] = [
'option_id' => $filter[0],
'value_id' => $filter[1],
];
}
}
$result->when($filters, function($query, $filters) {
$query->where(function($query) use ($filters) {
foreach($filters as $filter) {
$query->orWhere(function($query) use ($filter) {
$query->where('product_options_pivot.options_id', $filter['option_id'])
->where('product_options_pivot.value_id', $filter['value_id']);
});
}
});
});
return $result->paginate(48);
}`