mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Addressable;
|
|
use App\Classes\General\Interfaces\Contactable;
|
|
use App\Classes\General\Interfaces\Packable;
|
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
|
use App\Scopes\CustomerOrdersScope;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
class Order extends AbstractModel implements Addressable, Packable
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'orders';
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function companyModule(): belongsTo
|
|
{
|
|
return $this->belongsTo(CompanyModule::class, 'company_module_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function orderSteps(): morphMany
|
|
{
|
|
return $this->morphMany(Step::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function addresses(): morphMany
|
|
{
|
|
return $this->morphMany(Address::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function packingLists(): morphMany
|
|
{
|
|
return $this->morphMany(PackingList::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return HasManyThrough
|
|
*/
|
|
public function parcels(): HasManyThrough
|
|
{
|
|
return $this->HasManyThrough(Package::class, PackingList::class, 'owner_id', 'packing_list_id')->where('owner_type', Order::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany
|
|
*/
|
|
public function OrderRoles(): HasMany
|
|
{
|
|
return $this->HasMany(OrderRole::class, 'order_id');
|
|
}
|
|
|
|
|
|
protected static function booted()
|
|
{
|
|
// if (auth()->user()->type === RoleTypes::USER) {
|
|
// static::addGlobalScope(new CustomerOrdersScope);
|
|
// }
|
|
}
|
|
}
|