Merhaba,
Sayfadaki verileri listeledikten sonra adı, kodu, fiyat1,fiyat3,fiyat3,fiyat4, artan fiyat, azalan fiyat olarak filtre yaptırmaya çalışıyorum.
Listeleme yaparken öncelik fiyat4 yazılsın, yoksa fiyat3 ... şeklinde. Ürünl listesinde fiyat4 varsa listeleme yapıyor, eğer fiyat4 yok fiyat3 varsa listelemiyor.
Aynı şekilde ... ile ... fiyatı arasında arama yapmak istediğimde tüm fiyatlara göre arama yapamıyorum.
Bu hataları nasıl düzeltebilirim , kodları nasıl daha düzgün hale sokabilirim ?
Teşekkürler.
Kontrolcüm şu şekilde
public function category($categorySlug)
{
$category = Category::where('slug', $categorySlug)->first();
$category_id = $category->id;
$fiyatTipi = request('fiyatTipi');
$tarihTipi = request('tarihTipi');
$firstTime = request('first_time');
$name = request('name');
$code = request('code');
$airTipi = request('airline_id');
if(!is_null(request('min_price')))
{
$min = request('min_price');
}else{
$min = 1;
}
if(!is_null(request('max_price')))
{
$max = request('max_price');
}else{
$max = 999999;
}
$airlines = Airline::all();
// Filtre
if(empty($fiyatTipi))
{
//dd( 'fiyat',$category_id);
// Fiyata Göre Sırala
if ($fiyatTipi == 1)
{
$products = Product::where('category_id', $category_id)
->orderBy('price4','DESC')
->get();
}else{
$products = Product::where('category_id', $category_id)
->orderBy('price4','ASC')
->get();
}
}
if(empty($tarihTipi))
{
//dd( 'tarih',$category_id);
// Tarihe Göre Sırala
if ($tarihTipi == 1) // artan
{
$products = Product::where('category_id', $category_id)
->orderBy('first_time','asc')
->get();
}
if (empty($tarihTipi == 2)) // artan
{
$products = Product::where('category_id', $category_id)
->orderBy('first_time','desc')
->get();
}
}
if(empty($firstTime))
{
if(!is_null($name)){
//dd('bura2');
$products = Product::where('category_id', $category_id)
->where('name' ,'like', '%' . $name . '%')
->where('code' ,'like', '%' . $code . '%')
->where('airline_id', 'like', '%'.$airTipi)
->get();
}
else{
//dd('else');
$products = Product::where('category_id', $category_id)
->where('airline_id', 'like', '%'.$airTipi)
->where('code' ,'like', '%' . $code . '%')
->where('price3', '>', $min)
->where('price3', '<', $max)
->Where('price4', '>', $min)
->Where('price4', '<', $max)
//->whereBetween('price3', [$min, $max])
//->whereBetween('price4', [$min, $max])
->get();
//dd(\DB::getQueryLog());
}
}
else{
//tarih seçimi varsa
//dd('tarih seçilmiş');
$products = Product::where('category_id', $category_id)
->where('name' ,'like', '%' . $name . '%')
->where('code' ,'like', '%' . $code . '%')
->where('airline_id', 'like', '%'.$airTipi)
->whereBetween('price4', [$min, $max])
->whereMonth('first_time', $firstTime)
->get();
}
return view('category')
->with('description',Category::where('id',$category_id)->first()->get())
->with('products', $products)
->with('category',$category)
->with('title', $category->name)
->with('airlines',$airlines)
;
}