Skip to content

Commit

Permalink
[Update] Config Resource Model
Browse files Browse the repository at this point in the history
- Updated Permission and Role resources to use models specified in Spatie's `permission.php` config file
  • Loading branch information
kiritokatklian committed May 17, 2024
1 parent d2c8a5b commit 702b12d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ class Permission extends Resource
'roles',
];

/**
* Create a new resource instance.
*
* @param TModel|null $resource
* @return void
*/
public function __construct($resource = null)
{
static::$model = static::getModel();
$this->resource = $resource;
}

/**
* The model the resource corresponds to.
*/
public static function getModel()
{
return app(PermissionRegistrar::class)->getPermissionClass();
Expand Down
21 changes: 18 additions & 3 deletions src/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ class Role extends Resource
'permissions',
];

/**
* Create a new resource instance.
*
* @param TModel|null $resource
* @return void
*/
public function __construct($resource = null)
{
static::$model = static::getModel();
$this->resource = $resource;
}

/**
* The model the resource corresponds to.
*/
public static function getModel()
{
$object = app(PermissionRegistrar::class)->getRoleClass();
Expand Down Expand Up @@ -167,11 +182,11 @@ public function actions(NovaRequest $request)
{
return [];
}

/**
*
*
* Allow the permissions to replicate with the Role
*
*
* @return Role|HigherOrderTapProxy|mixed
*/
public function replicate()
Expand Down

0 comments on commit 702b12d

Please sign in to comment.