67 lines
1.3 KiB
PHP
67 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;
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = [
|
|
'parent_id',
|
|
'name',
|
|
'route_or_url',
|
|
'icon',
|
|
'enable',
|
|
'position',
|
|
'actives',
|
|
'deleteable',
|
|
];
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
protected $with = [
|
|
'childs',
|
|
];
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function parent()
|
|
{
|
|
return $this->hasOne(static::class, 'id', 'parent_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function childs()
|
|
{
|
|
return $this->hasMany(static::class, 'parent_id', 'id')
|
|
->with('childs')
|
|
->orderBy('position');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function permissions()
|
|
{
|
|
return $this->belongsToMany(Permission::class);
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function roles()
|
|
{
|
|
return $this->belongsToMany(Role::class);
|
|
}
|
|
}
|