PHP code example of mashyindustries / laraccess

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

    

mashyindustries / laraccess example snippets


// config/app.php
'providers' => [
    ...
    Mashy\Laraccess\LaraccessServiceProvider::class,
];

use Mashy\Laraccess\Traits\HasRoles;

class User
{
    use HasRoles;
    
    // ...
}

use Mashy\Laraccess\Models\Role;

$role = Role::create([
    'name' => 'Writer', //optional
    'slug' => 'writer', //

$roles = $user->roles(); // returns a collection

$user->assignRole('writer');

// you can also assign multiple roles at once
$user->assignRole('writer', 'admin');
$user->assignRole(['writer', 'admin']);

$user->removeRole('writer');

//all current roles will be removed from the user and replace by the array given
$user->syncRoles(['writer', 'admin']);

$user->hasRole('writer');

$user->hasAnyRole(['writer', 'admin']);

$user->hasAllRoles(['writer', 'admin']);

@role('writer')
I'm a writer!
@else
I'm not a writer...
@endrole

@hasanyrole(['writer', 'admin'])
I have one or more of these roles!
@else
I have none of these roles...
@endrole

@hasallroles(['writer', 'admin'])
I have all of these roles!
@else
I don't have all of these roles...
@endrole
bash
php artisan vendor:publish --provider="Mashy\Laraccess\LaraccessServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Mashy\Laraccess\LaraccessServiceProvider" --tag="config"