PHP code example of mkinyua53 / authorization

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

    

mkinyua53 / authorization example snippets


  Mkinyua53\Authorization\AuthorizationServiceProvider::class,

public function roles()
{
    return $this->belongsToMany(Role::class);
}

public function permissions()
{
    return $this->belongsToMany(Permission::class);
}

public function users()
{
    return $this->belongsToMany(User::class);
}

public function permissions()
{
    return $this->belongsToMany(Permission::class);
}

public function roles()
{
    return $this->belongsToMany(Role::class);
}

public function users()
{
    return $this->belongsToMany(User::class);
}


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        \Mkinyua53\Authorization\Authorization::routes();
    }
}

Route::group(['namespace' => '\Mkinyua53\Authorization'], function () {
    Route::resource('roles', 'RoleController', ['except' => ['create', 'edit']]);
    Route::resource('permissions', 'PermissionController', ['except' => ['create', 'edit']]);

    Route::post('roles/{role}/users/{user}/attach', 'RoleController@attachUser');
    Route::post('roles/{role}/permissions/{permission}/attach', 'RoleController@attachPermission');
    Route::post('roles/{role}/users/{user}/detach', 'RoleController@detachUser');
    Route::post('roles/{role}/permissions/{permission}/detach', 'RoleController@detachPermission');
    Route::post('roles/users/{user}/detach', 'RoleController@detachUserAll');
    Route::post('roles/permissions/{permission}/detach', 'RoleController@detachPermissionAll');

    Route::post('permissions/{permission}/users/{user}/attach', 'PermissionController@attachUser');
    Route::post('permissions/{permission}/users/{user}/detach', 'PermissionController@detachUser');
    Route::post('permissions/users/{user}/detach', 'PermissionController@detachUserAll');
});