57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Menu extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'menu_id',
|
|
'title',
|
|
'description',
|
|
'price',
|
|
'image',
|
|
'isActive',
|
|
'category_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'menu_id' => 'integer',
|
|
'title' => 'array',
|
|
'description' => 'array',
|
|
'isActive' => 'boolean',
|
|
];
|
|
|
|
public function getTitleAttribute($value)
|
|
{
|
|
$locale = app()->getLocale();
|
|
$titles = is_array($value) ? $value : json_decode($value, true);
|
|
return $titles[$locale] ?? $titles['en'] ?? '';
|
|
}
|
|
|
|
public function getDescriptionAttribute($value)
|
|
{
|
|
$locale = app()->getLocale();
|
|
$descriptions = is_array($value) ? $value : json_decode($value, true);
|
|
return $descriptions[$locale] ?? $descriptions['en'] ?? '';
|
|
}
|
|
|
|
public function setTitleAttribute($value)
|
|
{
|
|
$this->attributes['title'] = json_encode($value);
|
|
}
|
|
|
|
public function setDescriptionAttribute($value)
|
|
{
|
|
$this->attributes['description'] = json_encode($value);
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
}
|