SUBD_Transport_Company/app/Models/Delivery.php

50 lines
1.1 KiB
PHP
Raw Normal View History

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