vat_wms/app/Models/StockSection.php
2025-06-02 07:36:24 +02:00

44 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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();
}
}