feat: implement tour listing with sorting and pagination

This commit is contained in:
2026-08-17 16:37:11 +03:30
parent 5350cd1742
commit 9dc27863e2
8 changed files with 392 additions and 2 deletions
+22
View File
@@ -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()
{