65 lines
1.4 KiB
PHP
65 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class StockPosition extends Model
|
|
{
|
|
protected $table = 'stock_position';
|
|
protected $primaryKey = 'position_id';
|
|
public $timestamps = true;
|
|
|
|
protected $fillable = [
|
|
'position_symbol',
|
|
'position_name',
|
|
'shelf_id',
|
|
'capacity',
|
|
'temporary'
|
|
];
|
|
|
|
protected $appends = [
|
|
'storage_address',
|
|
];
|
|
|
|
public function getStorageAddressAttribute(): string
|
|
{
|
|
// calls your existing method, which will
|
|
// loadMissing the relations if needed
|
|
return $this->storageAddress();
|
|
}
|
|
|
|
public function shelf()
|
|
{
|
|
return $this->belongsTo(StockShelf::class, 'shelf_id');
|
|
}
|
|
|
|
public function sections()
|
|
{
|
|
return $this->hasMany(StockSection::class, 'position_id', 'position_id');
|
|
}
|
|
|
|
|
|
|
|
public function storageAddress(): string
|
|
{
|
|
// eager-load the whole hierarchy if not already
|
|
$this->loadMissing('shelf.rack.line.room');
|
|
|
|
|
|
$shelf = $this->shelf;
|
|
$rack = $shelf->rack;
|
|
$line = $rack->line;
|
|
$room = $line->room;
|
|
|
|
return sprintf(
|
|
'%s-%s-%s-%s-%s',
|
|
$room->room_symbol,
|
|
$line->line_symbol,
|
|
$rack->rack_symbol,
|
|
$shelf->shelf_symbol,
|
|
$this->position_symbol
|
|
);
|
|
|
|
}
|
|
}
|