first commit
This commit is contained in:
57
app/Models/Menu.php
Normal file
57
app/Models/Menu.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user