PHP code example of roundly-consulting / permissions-for-laravel

1. Go to this page and download the library: Download roundly-consulting/permissions-for-laravel 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/ */

    

roundly-consulting / permissions-for-laravel example snippets


use Illuminate\Foundation\Auth\User as Authenticatable;
use RoundlyConsulting\Permissions\Concerns\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

use RoundlyConsulting\Permissions\Facades\Permissions;

Permissions::permission('posts.view');                    // find or create
Permissions::permission('posts.edit');

Permissions::role('editor')->givePermissionTo('posts.view', 'posts.edit');

Permissions::for($user)->assignRole('editor');

$user->hasRole('editor');                                  // true
$user->getAllPermissions()->pluck('name');                 // direct + via roles: posts.view, posts.edit
$user->can('posts.edit');                                  // true

Route::get('/posts', PostsController::class)->middleware('can:posts.view');
bash
composer vendor:publish --tag="permissions-migrations"
php artisan migrate