103 lines
2.5 KiB
PHP
103 lines
2.5 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\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Modules\Customer\Models\Review;
|
|
|
|
class FoodItem extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'restaurant_id',
|
|
'category_id',
|
|
'menu_category_id',
|
|
'menu_section_id',
|
|
'name',
|
|
'slug',
|
|
'description',
|
|
'food_type',
|
|
'points',
|
|
'is_featured',
|
|
'is_party',
|
|
'is_dinner',
|
|
'is_lunch',
|
|
'is_popular_item',
|
|
'is_chef_special',
|
|
'image',
|
|
'prep_time',
|
|
'cooking_time',
|
|
'vat',
|
|
'pst',
|
|
'ingredients_cost',
|
|
'allergens',
|
|
'notes',
|
|
'status',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
public const TABLE_NAME = 'food_items';
|
|
|
|
protected $table = self::TABLE_NAME;
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FoodCategory::class, 'category_id')->select('id', 'name');
|
|
}
|
|
|
|
public function menuCategory(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MenuCategory::class)->select('id', 'name');
|
|
}
|
|
|
|
public function menuSection(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MenuSection::class)->select('id', 'name');
|
|
}
|
|
|
|
public function variants(): HasMany
|
|
{
|
|
return $this->hasMany(FoodVariant::class, 'food_item_id')->with('unit');
|
|
}
|
|
|
|
public function defaultVariant(): HasOne
|
|
{
|
|
return $this->hasOne(FoodVariant::class, 'food_item_id')->with('unit')->where('is_default', true);
|
|
}
|
|
|
|
public function availabilities(): HasMany
|
|
{
|
|
return $this->hasMany(FoodAvailability::class, 'food_item_id');
|
|
}
|
|
|
|
public function addons(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Addon::class, 'addon_food', 'food_item_id', 'addon_id')
|
|
->using(AddonFood::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function reviews(): HasMany
|
|
{
|
|
return $this->hasMany(Review::class, 'food_item_id')->with('images');
|
|
}
|
|
|
|
public function scopeChefSpecial($query, int $value): mixed
|
|
{
|
|
return $query->where('is_chef_special', $value);
|
|
}
|
|
|
|
public function scopePopular($query, int $value): mixed
|
|
{
|
|
return $query->where('is_popular_item', $value);
|
|
}
|
|
}
|