PHP code example of saritasa / roles-simple

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

    

saritasa / roles-simple example snippets


'providers' => array(
    // ...
    Saritasa\Roles\RolesServiceProvider::class,
)

class User extends Model implements IHasRoles
{
    uses HasRoles
}

if ($user->hasRole(Roles::ADMIN)) { ... }}
$user->role->name;
 vendor/bin/phpcs
 vendor/bin/phpcbf
 vendor/bin/phpunit
bash
php artisan vendor:publish --provider=Saritasa\\Roles\\RolesServiceProvider

class AddRoles extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Role::firstOrCreate(['name' => 'User', 'slug' => 'user']);
        Role::firstOrCreate(['name' => 'Admin', 'slug' => 'admin']);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Role::whereSlug('user')->delete();
        Role::whereSlug('admin')->delete();
    }
}