初始化项目
This commit is contained in:
58
app/Models/Auth/Permission.php
Normal file
58
app/Models/Auth/Permission.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_permissions';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'type',
|
||||
'parent_id',
|
||||
'route',
|
||||
'component',
|
||||
'meta',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'meta' => 'array',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联角色
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'auth_role_permission', 'permission_id', 'role_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子权限
|
||||
*/
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Permission::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父权限
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user