新增單位管理以及一些功能修正

This commit is contained in:
2026-01-08 11:52:25 +08:00
parent eca2f38395
commit 48115082e5
19 changed files with 872 additions and 246 deletions

View File

@@ -17,10 +17,10 @@ class Product extends Model
'category_id',
'brand',
'specification',
'base_unit',
'large_unit',
'base_unit_id',
'large_unit_id',
'conversion_rate',
'purchase_unit',
'purchase_unit_id',
];
protected $casts = [
@@ -35,6 +35,21 @@ class Product extends Model
return $this->belongsTo(Category::class);
}
public function baseUnit(): BelongsTo
{
return $this->belongsTo(Unit::class, 'base_unit_id');
}
public function largeUnit(): BelongsTo
{
return $this->belongsTo(Unit::class, 'large_unit_id');
}
public function purchaseUnit(): BelongsTo
{
return $this->belongsTo(Unit::class, 'purchase_unit_id');
}
public function vendors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Vendor::class)->withPivot('last_price')->withTimestamps();

17
app/Models/Unit.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model
{
/** @use HasFactory<\Database\Factories\UnitFactory> */
use HasFactory;
protected $fillable = [
'name',
'code',
];
}