66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\Restaurant\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
|
||
|
|
class FoodVariant extends Model
|
||
|
|
{
|
||
|
|
use SoftDeletes;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'restaurant_id',
|
||
|
|
'food_item_id',
|
||
|
|
'name',
|
||
|
|
'sku',
|
||
|
|
'barcode',
|
||
|
|
'price',
|
||
|
|
'offer_price',
|
||
|
|
'discount',
|
||
|
|
'unit_id',
|
||
|
|
'image',
|
||
|
|
'description',
|
||
|
|
'is_default',
|
||
|
|
'stock_tracking',
|
||
|
|
'ingredients_cost',
|
||
|
|
'profit_margin',
|
||
|
|
'alert_stock_quantity',
|
||
|
|
'combo_type',
|
||
|
|
'is_active_offer',
|
||
|
|
'offer_start_at',
|
||
|
|
'offer_end_at',
|
||
|
|
'status',
|
||
|
|
'created_at',
|
||
|
|
'updated_at',
|
||
|
|
'deleted_at',
|
||
|
|
];
|
||
|
|
|
||
|
|
public const TABLE_NAME = 'food_variants';
|
||
|
|
|
||
|
|
protected $table = self::TABLE_NAME;
|
||
|
|
|
||
|
|
public function food(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(FoodItem::class, 'food_item_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getDefaultVariant($foodId): ?FoodVariant
|
||
|
|
{
|
||
|
|
return self::where('food_item_id', $foodId)->where('is_default', true)->first();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function ingredients(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(FoodVariantIngredient::class, 'food_variant_id', 'id')
|
||
|
|
->with('ingredient');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function unit(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Unit::class)->select('id', 'name', 'short_name');
|
||
|
|
}
|
||
|
|
}
|