feat(menu): enhance Menu and TenantMenu models with parent-child relationships and static content support
This commit is contained in:
@@ -5,7 +5,9 @@ namespace App\Domains\Menu\Models;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
@@ -15,18 +17,41 @@ class Menu extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'parent_menu_code',
|
||||
'content_type',
|
||||
'static_content_schema',
|
||||
'route',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'static_content_schema' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_menu_code', 'code');
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_menu_code', 'code');
|
||||
}
|
||||
|
||||
public function tenants(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
Tenant::class,
|
||||
'tenant_menues',
|
||||
'tenants_menues',
|
||||
'menu_code',
|
||||
'tenant_codigo',
|
||||
'tenant_code',
|
||||
'code',
|
||||
'codigo'
|
||||
)->withTimestamps();
|
||||
)
|
||||
->using(TenantMenu::class)
|
||||
->withPivot('static_content')
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user