laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

Understanding and implementing the kodiene/laravel-acl package

Open udemethegrtman opened this issue 9 years ago • 0 comments
trafficstars

Hi @everyone i have searched for the roles and permission for authentifying both users and admin in my app, with a lot tested failed due to to not supporting laravel 5.2 i ended up with this (laravel-acl) so far i have not had to hit my head on the wall for this one, that is by the way.

I have installed the package, and tweaked the config to support 5.2 based on issues other users raised about the package, and everything seems to be fine until i found out am not been permitted to view the admin page as a user which i want to achieve but not all users are permitted to.

This is where i created my roles and permission Route::get('db', function() {

/* Roles for user and admin */


$roleAdmin = new Role();
$roleAdmin->name = 'Admin | udeme samuel';
$roleAdmin->slug = 'admin';
$roleAdmin->description = 'Super admin | manage administration privileges';
$roleAdmin->save();


$user = User::where('email', '=', '[email protected]')->first();

$user->assignRole($roleAdmin->id);

exit();


/* assign permission */

$permission = new Permission();
$permUser = $permission->create([ 
    'name'        => 'admin',
    'slug'        => [          // pass an array of permissions.
    'create'     => true,
    'view'       => true,
    'update'     => true,
    'delete'     => true,
    'view.phone' => true
],
    'description' => 'manage admin and user permissions and views access'
]);

$roleAdmin = Role::first(); // administrator

$roleAdmin->assignPermission($permUser->id);
});

The issue is when i log in as a user with admin access the admin@login page redirects me to 401 page error, This is my route for the proctected pages.

Route::group(['middleware' => ['web']], function () {

    Route::get('admin@login', [
    'uses'=> 'Admin\AdminAccountController@index',
    'middleware'   => ['auth', 'acl'],
    'is'           => 'admin']);
}

This is what i want to achieve, i want to have three users accounts that have roles as admin and can access admin pages and user pages but guest cannot view the admin pages insted they view a custom 401 error page.

What can i do, besides i will like to understand the concept of roles and permission in protecting pages.

udemethegrtman avatar Jun 29 '16 09:06 udemethegrtman