PHP code example of aammui / role-permission

1. Go to this page and download the library: Download aammui/role-permission 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/ */

    

aammui / role-permission example snippets


// App\Exceptions\Handler.php;
use Aammui\RolePermission\Exception\UserNotLoginException;
use Aammui\RolePermission\Exception\RoleDoesNotExistException;

....

public function render($request, Throwable $exception)
{
    if ($exception instanceof UserNotLoginException) {
        return redirect('/login')
            ->with('error', $exception->getMessage());
    }
    
    if ($exception instanceof RoleDoesNotExistException) {
        return redirect('/login')
            ->with('error', $exception->getMessage());
    }

    return parent::render($request, $exception);
}
App\Http\Kernel.php

Route::group(['middleware' => ['role:system admin|database admin','permission:read article']], function () {
    //
});

php artisan vendor:publish --provider="Aammui\RolePermission\RolePermissionServiceProvider"
php artisan migrate
public function getRoles(): array
public function hasGotRole(array $roles): bool
app\Exceptions\Handler.php