diff --git a/src/AttachToRole.php b/src/AttachToRole.php index 1cc6660..36c504f 100644 --- a/src/AttachToRole.php +++ b/src/AttachToRole.php @@ -24,7 +24,7 @@ class AttachToRole extends Action */ public function handle(ActionFields $fields, Collection $models) { - $role = Role::getModel()->find($fields['role']); + $role = Role::getObject()->find($fields['role']); foreach ($models as $model) { $role->givePermissionTo($model); } @@ -39,7 +39,7 @@ public function handle(ActionFields $fields, Collection $models) public function fields(NovaRequest $request) { return [ - Select::make('Role')->options(Role::getModel()->get()->pluck('name', 'id')->toArray())->displayUsingLabels(), + Select::make('Role')->options(Role::getObject()->get()->pluck('name', 'id')->toArray())->displayUsingLabels(), ]; } } diff --git a/src/Permission.php b/src/Permission.php index 79d0016..6eac94f 100644 --- a/src/Permission.php +++ b/src/Permission.php @@ -63,8 +63,10 @@ public function __construct($resource = null) /** * The model the resource corresponds to. + * + * @return string */ - public static function getModel() + public static function getModel(): string { return app(PermissionRegistrar::class)->getPermissionClass(); } diff --git a/src/Role.php b/src/Role.php index c6d3dfd..a44fcbc 100644 --- a/src/Role.php +++ b/src/Role.php @@ -63,12 +63,20 @@ public function __construct($resource = null) /** * The model the resource corresponds to. + * + * @return string */ - public static function getModel() + public static function getModel(): string { - $object = app(PermissionRegistrar::class)->getRoleClass(); + return app(PermissionRegistrar::class)->getRoleClass(); + } - return \is_string($object) ? app($object) : $object; + /** + * An object instance of the model the resource corresponds to. + */ + public static function getObject() + { + return app(static::getModel()); } /**