feat: update models and relationships
This commit is contained in:
@@ -9,6 +9,8 @@ namespace App\Models;
|
||||
use App\Enums\FlightStatus;
|
||||
use App\Enums\FlightTripType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -65,6 +67,28 @@ class Flight extends Model
|
||||
'status',
|
||||
'trip_type'
|
||||
];
|
||||
#[Scope]
|
||||
protected function applySort(Builder $query): void
|
||||
{
|
||||
switch (request()->input('sort')) {
|
||||
case 'popularity':
|
||||
$query->withCount('bookings')
|
||||
->orderByDesc('bookings_count');
|
||||
break;
|
||||
|
||||
case 'lowest':
|
||||
$query->orderBy('price');
|
||||
break;
|
||||
|
||||
case 'highest':
|
||||
$query->orderByDesc('price');
|
||||
break;
|
||||
|
||||
default:
|
||||
$query->latest('id'); // همهی پروازها
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function airline()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user