44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
class StockSection extends Model
|
||
{
|
||
protected $table = 'stock_section';
|
||
protected $primaryKey = 'section_id';
|
||
public $timestamps = true;
|
||
|
||
protected $fillable = [
|
||
'section_symbol',
|
||
'section_name',
|
||
'position_id',
|
||
'capacity',
|
||
'retrievable'
|
||
];
|
||
|
||
public function position()
|
||
{
|
||
return $this->belongsTo(StockPosition::class, 'position_id', 'position_id');
|
||
}
|
||
|
||
// If you have a StockEntry model, you can set up a many-to-many via the pivot:
|
||
public function entries()
|
||
{
|
||
return $this->belongsToMany(
|
||
StockEntry::class, // your entry model
|
||
'stock_entries2section', // pivot table
|
||
'section_id', // this modelʼs FK on pivot
|
||
'entry_id' // other modelʼs FK on pivot
|
||
)
|
||
->withPivot('count')
|
||
->withTimestamps();
|
||
}
|
||
|
||
public function occupied(): bool
|
||
{
|
||
return $this->entries()->exists();
|
||
}
|
||
|
||
}
|