From db178150fb66e4b6ce9eb3e1cb28cf20f1752027 Mon Sep 17 00:00:00 2001 From: ArshiaMohammadei Date: Mon, 26 May 2025 10:39:09 +0330 Subject: [PATCH] Update EntrustPermissionTrait.php Improve type hinting, naming, and readability: - Added return types: BelongsToMany for roles(), void for boot method - Renamed boot() to bootEntrustPermissionTrait to avoid trait conflicts - Replaced sync([]) with detach() for clarity - Removed unnecessary return true in event listener - Added import for BelongsToMany - Improved formatting and line breaks --- src/Entrust/Traits/EntrustPermissionTrait.php | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Entrust/Traits/EntrustPermissionTrait.php b/src/Entrust/Traits/EntrustPermissionTrait.php index d2a460f6..81ae2d6a 100644 --- a/src/Entrust/Traits/EntrustPermissionTrait.php +++ b/src/Entrust/Traits/EntrustPermissionTrait.php @@ -1,4 +1,9 @@ -belongsToMany(Config::get('entrust.role'), Config::get('entrust.permission_role_table'), Config::get('entrust.permission_foreign_key'), Config::get('entrust.role_foreign_key')); + return $this->belongsToMany( + Config::get('entrust.role'), + Config::get('entrust.permission_role_table'), + Config::get('entrust.permission_foreign_key'), + Config::get('entrust.role_foreign_key') + ); } /** - * Boot the permission model - * Attach event listener to remove the many-to-many records when trying to delete + * Boot the permission model. + * Attach event listener to remove the many-to-many records when trying to delete. * Will NOT delete any records if the permission model uses soft deletes. - * - * @return void|bool */ - public static function boot() + public static function bootEntrustPermissionTrait(): void { - parent::boot(); - - static::deleting(function($permission) { - if (!method_exists(Config::get('entrust.permission'), 'bootSoftDeletes')) { - $permission->roles()->sync([]); + static::deleting(function ($permission) { + if (! method_exists(Config::get('entrust.permission'), 'bootSoftDeletes')) { + $permission->roles()->detach(); } - - return true; }); } }