feat: implement flight sorting and pagination
This commit is contained in:
@@ -9,6 +9,7 @@ namespace App\Models;
|
||||
use App\Enums\FlightStatus;
|
||||
use App\Enums\FlightTripType;
|
||||
use Carbon\Carbon;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
@@ -89,10 +90,42 @@ class Flight extends Model
|
||||
}
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function filterFrom(Builder $query, ?string $cityName = null): void
|
||||
{
|
||||
if ($cityName) {
|
||||
$query->whereHas('origin_airport.city', function (Builder $q) use ($cityName) {
|
||||
$q->where('name', 'LIKE', "%$cityName%");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function filterTo(Builder $query, ?string $cityName = null): void
|
||||
{
|
||||
if ($cityName) {
|
||||
$query->whereHas('airport.city', function (Builder $q) use ($cityName) {
|
||||
$q->where('name', 'LIKE', "%$cityName%");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function airline()
|
||||
{
|
||||
return $this->belongsTo(Airline::class);
|
||||
}
|
||||
#[Scope]
|
||||
protected function filterDepartureDate(Builder $query, ?string $dateInput = null): void
|
||||
{
|
||||
if (!$dateInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$date = Verta::parse($dateInput)->datetime();
|
||||
|
||||
$query->whereDate('departure_time', $date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function origin_airport()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user