feat: add created_by field handling for flights
This commit is contained in:
+46
-1
@@ -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;
|
||||
|
||||
@@ -20,6 +22,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $image
|
||||
* @property string $views
|
||||
* @property int $travel_type_id
|
||||
* @property int $created_by
|
||||
* @property float $price
|
||||
* @property Carbon $departure_date
|
||||
* @property int $status
|
||||
@@ -50,6 +53,7 @@ class Tour extends Model
|
||||
'views',
|
||||
'travel_type_id',
|
||||
'price',
|
||||
'created_by',
|
||||
'departure_date',
|
||||
'status'
|
||||
];
|
||||
@@ -70,4 +74,45 @@ class Tour extends Model
|
||||
{
|
||||
return $this->morphMany(Reservation::class, 'reservable');
|
||||
}
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function applySearch(Builder $query, ?array $filters = []): void
|
||||
{
|
||||
$query->when($filters['search'] ?? null, function ($query, $search) {
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
|
||||
$q->where('title', 'like', "%{$search}%")
|
||||
->orWhere('summary', 'like', "%{$search}%");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[Scope]
|
||||
public function filterType(Builder $query, $type = null): void
|
||||
{
|
||||
$query->when($type !== null && $type !== '', function($query) use ($type){
|
||||
|
||||
$query->where('travel_type_id', $type);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function sort(Builder $query, $sort = null): void
|
||||
{
|
||||
if ($sort == 'price_asc') {
|
||||
|
||||
$query->orderBy('price', 'asc');
|
||||
|
||||
}
|
||||
|
||||
if ($sort == 'price_desc') {
|
||||
|
||||
$query->orderBy('price', 'desc');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user