55 lines
1.6 KiB
PHP
Executable File
55 lines
1.6 KiB
PHP
Executable File
<?php
|
|
namespace App\Models\Auth;
|
|
|
|
use Dcat\Admin\Models\Menu;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class MenuModel extends Menu
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::treeBoot();
|
|
|
|
static::saved(function ($model) {
|
|
$model->flushCache();
|
|
});
|
|
static::deleting(function ($model) {
|
|
$model->mPermissions()->delete();
|
|
$model->mRoles()->delete();
|
|
$model->flushCache();
|
|
});
|
|
}
|
|
|
|
public function roles() :BelongsToMany
|
|
{
|
|
$pivotTable = config('admin.database.role_menu_table');
|
|
|
|
$relatedModel = config('admin.database.roles_model');
|
|
|
|
return $this->belongsToMany($relatedModel, $pivotTable, 'menu_id', 'role_id')->withTimestamps()
|
|
->withoutTrashed()->whereNull($pivotTable.'.deleted_at');
|
|
}
|
|
|
|
public function permissions() :BelongsToMany
|
|
{
|
|
$pivotTable = config('admin.database.permission_menu_table');
|
|
|
|
$relatedModel = config('admin.database.permissions_model');
|
|
|
|
return $this->belongsToMany($relatedModel, $pivotTable, 'menu_id', 'permission_id')->withTimestamps()
|
|
->withoutTrashed()->whereNull($pivotTable.'.deleted_at');
|
|
}
|
|
|
|
public function mPermissions() {
|
|
return $this->hasMany(PermissionMenuModel::class, 'menu_id', 'id');
|
|
}
|
|
|
|
public function mRoles() {
|
|
return $this->hasMany(RoleMenuModel::class, 'menu_id', 'id');
|
|
}
|
|
}
|
|
|