1. Go to this page and download the library: Download ssntpl/laravel-acl 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/ */
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Ssntpl\LaravelAcl\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
}
$user = User::find(1);
$project = Project::find(42);
$user->assignRole('admin', $project); // scoped role
$user->assignRole('super-admin', null, now()->addMonth()); // global role with expiration
if ($user->hasRole('admin', $project)) {
// subject is an admin of this project
}
$role = $user->getRole(); // global role assignment (resource = null)
if ($role && $role->can('articles.publish')) {
// allowed via direct or implied permission (and not explicitly denied)
}