mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
class Transport extends AbstractModel
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'transport_arrangements';
|
|
|
|
protected $fillable = ['status', 'drop_date'];
|
|
|
|
protected $dates = ['dispatch_date', 'drop_date'];
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function owner(): morphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function schedules(): morphMany
|
|
{
|
|
return $this->morphMany(Schedule::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @param $query
|
|
* @return mixed
|
|
*/
|
|
public function scopeDispatched($query){
|
|
return $query->where('dispatch_date', '<', Carbon::now())->whereIn('status', [ApprovalStatus::APPROVED]);
|
|
}
|
|
|
|
/**
|
|
* @param $query
|
|
* @return mixed
|
|
*/
|
|
public function scopeDropped($query){
|
|
return $query->where('drop_date', '<', Carbon::now())->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
|
}
|
|
}
|