Files
hyperf_rbac_framework_serve…/app/Model/AdminRole.php
2025-09-12 15:23:08 +08:00

97 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Events\Deleting;
use Hyperf\Database\Model\Relations\BelongsToMany;
/**
* @property int $id
* @property string $name
* @property string $code
* @property int $status
* @property int $sort
* @property int $created_by
* @property int $updated_by
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $remark
*/
class AdminRole extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'admin_role';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'id',
'name',
'code',
'status',
'sort',
'created_by',
'updated_by',
'created_at',
'updated_at',
'remark'
];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'id' => 'integer',
'status' => 'integer',
'sort' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* @return BelongsToMany
*/
public function adminMenus(): BelongsToMany
{
return $this->belongsToMany(
AdminMenu::class,
'role_belongs_menu',
'role_id',
'menu_id'
);
}
/**
* @return BelongsToMany
*/
public function adminUsers(): BelongsToMany
{
return $this->belongsToMany(
AdminUser::class,
'admin_user_belongs_role',
'role_id',
'user_id'
);
}
/**
* @param Deleting $event
* @return void
*/
public function deleting(Deleting $event): void
{
$this->adminUsers()->detach();
$this->adminMenus()->detach();
}
}