Skip to content

Commit

Permalink
[Fix] Role Resource
Browse files Browse the repository at this point in the history
- Added `Role::getObject` that returns an object instance of the model
- Refactored `Role::getModel` to return string similar to `Permission::getModel`
  • Loading branch information
kiritokatklian committed May 18, 2024
1 parent d4135f4 commit fc9c667
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/AttachToRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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(),
];
}
}
4 changes: 3 additions & 1 deletion src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 11 additions & 3 deletions src/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit fc9c667

Please sign in to comment.