Files

68 lines
1.6 KiB
PHP

<?php
namespace Modules\Restaurant\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Ingredient extends Model
{
use SoftDeletes;
protected $fillable = [
'restaurant_id',
'name',
'unit_id',
'stock_quantity',
'cost_per_unit',
'low_stock_alert',
'supplier_id',
'last_purchase_price',
'last_purchase_date',
'conversion_factor',
'reserved_quantity',
'wastage_quantity',
'category',
'notes',
'status',
'image',
'created_at',
'updated_at',
'deleted_at',
];
public const TABLE_NAME = 'ingredients';
protected $table = self::TABLE_NAME;
public function foodVariants(): BelongsToMany
{
return $this->belongsToMany(FoodVariant::class, 'food_variant_ingredients')
->withPivot(['quantity', 'wastage_percentage', 'unit_conversion_factor', 'optional', 'notes'])
->withTimestamps();
}
public function purchaseItems(): HasMany
{
return $this->hasMany(PurchaseItem::class);
}
public function stock(): HasMany
{
return $this->hasMany(Stock::class);
}
public function damages(): HasMany
{
return $this->hasMany(IngredientDamage::class);
}
public function unit(): BelongsTo
{
return $this->belongsTo(Unit::class)->select('id', 'name', 'short_name');
}
}