mgsmus ilgili bölümler olacağını düşündüğüm kısımlar aşağıdaki gibi. Yani şimdi bu şekliyle çalışırken neden böyle bir sorun verdi hiçbir fikrim yok :/
public static $allowedSortingOptions = array (
'name desc' => 'Name - desc',
'name asc' => 'Name - asc',
'year desc' => 'Year - desc',
'year asc' => 'Year - asc',
'sort_order asc' => 'Sort - asc',
'sort_order desc' => 'Sort - desc',
'created_at desc' => 'created_at desc',
'price desc' => 'Price - desc',
'price asc' => 'Price - asc',
);
public function scopeListFrontEnd($query, $options = []){
extract(array_merge([
'page' => 1,
'perPage' => 10,
'sort' => 'created_at desc',
'leisure' => null,
'kitchen' => null,
'electronics' => null,
'comfort' => null,
'deck' => null,
'startYear' => null,
'endYear' => null,
'type' => null,
'cat' => null,
'des' => null,
'cabin' => null,
'postFrom' => null,
'postTo' => null,
'minPrice' => null,
'maxPrice' => null,
], $options));
if(!is_array ($sort)){
$sort = [$sort];
}
foreach ($sort as $_sort){
if(in_array($_sort, array_keys(self::$allowedSortingOptions))){
$parts = explode(' ', $_sort);
if(count($parts) < 2){
array_push($parts, 'desc');
}
list($sortField, $sortDirection) = $parts;
if($sortField == 'price'){
$query->join('tablo2', 'tablo1.id', '=', 'tablo2.product_id')
->where(function($sq) use ($postFrom) {
$sq->whereDate('start_date', '<=', $postFrom[0])
->whereDate('end_date', '>=', $postFrom[0]);
})->orWhere(function($ssq) use ($postTo) {
$ssq->whereDate('start_date', '<=', $postTo[0])
->whereDate('end_date', '>=', $postTo[0]);
})->orderByRaw("CASE WHEN daily IS NOT NULL THEN daily ELSE old_daily END $sortDirection");
}else{
$query->orderBy($sortField, $sortDirection);
}
}
}
if($postFrom != null) {
if(!is_array($postFrom)){
$postFrom = [$postFrom];
}
foreach ($postFrom as $postFr){
$query->whereHas('sPrices', function($q) use ($postFr, $postTo){
$q->when($postFr=='0', function ($sq) {
$sq->where('id', '>', '0');
}, function ($ssq) use ($postFr, $postTo) {
$ssq->whereDate('start_date', '<=', $postFr);
$ssq->whereDate('end_date', '>=', $postFr);
$ssq->orWhereDate('start_date', '<=', $postTo[0]);
$ssq->whereDate('end_date', '>=', $postTo[0]);
});
});
}
}
...şeklinde devam ediyor