feat: implement tour listing with sorting and pagination
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -50,6 +52,26 @@ class Tour extends Model
|
||||
'file_id',
|
||||
'tour_type'
|
||||
];
|
||||
#[Scope]
|
||||
protected function applySort(Builder $query, ?string $sort = null): void
|
||||
{
|
||||
switch ($sort) {
|
||||
|
||||
case 'lowest':
|
||||
$query->withMin('tourDepartures', 'price')
|
||||
->orderBy('tour_departures_min_price');
|
||||
break;
|
||||
|
||||
case 'highest':
|
||||
$query->withMax('tourDepartures', 'price')
|
||||
->orderByDesc('tour_departures_max_price');
|
||||
break;
|
||||
|
||||
default:
|
||||
$query->orderByDesc('id');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function flight()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user