SUBD_Transport_Company/app/Models/Delivery.php
2024-01-30 11:21:30 +04:00

50 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use App\Enums\StatusEnum;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Delivery extends Model
{
use HasFactory;
protected $fillable = [
'address',
'status',
'receiver',
'sender',
'receiver_phone',
'sender_phone',
'sending_date',
'delivery_date',
'user_id',
'warehouse_id',
];
protected $casts = [
'status' => StatusEnum::class,
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function warehouse(): BelongsTo
{
return $this->belongsTo(Warehouse::class);
}
public function scopeFilter(Builder $query): void
{
$address = request('address');
$query->when($address, function (Builder $query, $address){
$query->whereRaw('CONCAT (address) ilike ?', ["$address%"]);
});
}
}