55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Product extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'code',
|
|
'name',
|
|
'category_id',
|
|
'brand',
|
|
'specification',
|
|
'base_unit',
|
|
'large_unit',
|
|
'conversion_rate',
|
|
'purchase_unit',
|
|
];
|
|
|
|
protected $casts = [
|
|
'conversion_rate' => 'decimal:4',
|
|
];
|
|
|
|
/**
|
|
* Get the category that owns the product.
|
|
*/
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function vendors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Vendor::class)->withPivot('last_price')->withTimestamps();
|
|
}
|
|
|
|
public function inventories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
{
|
|
return $this->hasMany(Inventory::class);
|
|
}
|
|
|
|
public function warehouses(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Warehouse::class, 'inventories')
|
|
->withPivot(['quantity', 'safety_stock', 'location'])
|
|
->withTimestamps();
|
|
}
|
|
}
|