Files
portal/app/Models/Package.php
T

77 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasOneDeep;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
class Package extends AbstractModel
{
use HasRelationships;
use SoftDeletes;
protected $table = 'packages';
/**
* @return BelongsTo
*/
public function packingList(): BelongsTo
{
return $this->belongsTo(PackingList::class, 'packing_list_id');
}
/**
* @return HasManyThrough
*/
public function shippingTransports(): hasManyThrough
{
return $this->hasManyDeep(Transport::class, [PackingList::class, ContainerPackingList::class, Container::class], ['id', 'packing_list_id', 'id', ['owner_type', 'owner_id']], ['packing_list_id', 'id', 'container_id', null]);
}
/**
* @return HasManyThrough
*/
public function shippingSchedules(): hasManyThrough
{
return $this->hasManyDeep(Schedule::class, [PackingList::class, ContainerPackingList::class, Container::class, Transport::class], ['id', 'packing_list_id', 'id', ['owner_type', 'owner_id'], ['owner_type', 'owner_id']], ['packing_list_id', 'id', 'container_id', null, null]);
}
/**
* @return HasManyThrough
*/
public function deliveryTransports(): hasManyThrough
{
return $this->hasManyDeep(Transport::class, [PackingList::class], ['id', ['owner_type', 'owner_id']], ['packing_list_id', null]);
}
/**
* @return HasManyThrough
*/
public function deliverySchedules(): hasManyThrough
{
return $this->hasManyDeep(Schedule::class, [PackingList::class, Transport::class], ['id', ['owner_type', 'owner_id'], ['owner_type', 'owner_id']], ['packing_list_id', null, null]);
}
/**
* @return hasOneDeep
*/
public function container(): hasOneDeep
{
return $this->hasOneDeep(Container::class, [PackingList::class, ContainerPackingList::class], ['id', 'packing_list_id', 'id'], ['packing_list_id', 'id', 'container_id']);
}
/**
* @return hasOneDeep
*/
public function transport(): hasOneDeep
{
return $this->hasOneDeep(Transport::class, [PackingList::class], ['id', ['owner_type', 'owner_id']], ['packing_list_id', null]);
}
}