Skip to content

Commit

Permalink
[Merge] fix: Role Resource #34
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritokatklian authored May 18, 2024
2 parents d4135f4 + fc9c667 commit a1dea5d
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 a1dea5d

Please sign in to comment.