1. Go to this page and download the library: Download guava/simple-permissions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Guava\SimplePermissions\Concerns\HasAccessControl;
public class User extends Model
{
use HasAccessControl;
// ...
}
public enum PostPermissions: string implements \Guava\SimplePermissions\Contracts\Permission
{
case VIEW = 'view';
// ...Other redefined permissions
}
public class SuperAdmin implements \Guava\SimplePermissions\Contracts\Role
{
public function permissions() : array
{
return [
// Add permissions here
// Either one by one, such as:
PostPermissions::VIEW,
// or all at once:
...PostPermissions::cases()
];
}
}
$user->can(PostPermissions::VIEW)
use Guava\SimplePermissions\Concerns\HasAuthorization;
use App\Auth\Permissions\PostPermissions;
public class PostResource extends Resource
{
use HasAuthorization;
protected static string $permissions = PostPermissions::class;
// ...
}