84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class Flight
|
|
*
|
|
* @property int $id
|
|
* @property string|null $airline
|
|
* @property string|null $flight_number
|
|
* @property string|null $origin
|
|
* @property string|null $destination
|
|
* @property Carbon|null $departure_date
|
|
* @property Carbon|null $departure_time
|
|
* @property Carbon|null $arrival_time
|
|
* @property string|null $flight_class
|
|
* @property int|null $capacity
|
|
* @property float|null $price
|
|
* @property string|null $image
|
|
* @property string|null $views
|
|
* @property int|null $status
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class Flight extends Model
|
|
{
|
|
protected $table = 'flights';
|
|
public static $snakeAttributes = false;
|
|
|
|
protected $casts = [
|
|
'departure_date' => 'datetime',
|
|
'departure_time' => 'datetime',
|
|
'arrival_time' => 'datetime',
|
|
'capacity' => 'int',
|
|
'price' => 'float',
|
|
'status' => 'int'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'airline',
|
|
'flight_number',
|
|
'origin',
|
|
'destination',
|
|
'departure_date',
|
|
'departure_time',
|
|
'arrival_time',
|
|
'flight_class',
|
|
'capacity',
|
|
'price',
|
|
'image',
|
|
'views',
|
|
'status'
|
|
];
|
|
|
|
#[Scope]
|
|
public function applySearch(Builder $query, array $filters): void
|
|
{
|
|
$query
|
|
->when($filters['origin'] ?? null, function ($query, $origin) {
|
|
$query->where('origin', $origin);
|
|
})
|
|
->when($filters['destination'] ?? null, function ($query, $destination) {
|
|
$query->where('destination', $destination);
|
|
})
|
|
->when($filters['departure_date'] ?? null, function ($query, $date) {
|
|
$query->whereDate('departure_date', $date);
|
|
})
|
|
->when($filters['passengers'] ?? null, function ($query, $passengers) {
|
|
$query->where('capacity', '>=', $passengers);
|
|
});
|
|
}
|
|
}
|