0

Can you give me advice what to do. I am following this tutorial: Laravel 5.6 - User Roles and Permissions (ACL) using Spatie Tutorial

All good. But in the end, I have only access to users page and cannot create new user because there are not roles in the list. In the pages - products and roles gives me a message from the handler: ["User have not permission for this page access."]

I have only permission seeds:

    <?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;

class PermissionTableSeeder extends Seeder
{
  /**
   * Run the database seeds.
   *
   * @return void
   */
  public function run()
  {
     $permissions = [
         'role-list',
         'role-create',
         'role-edit',
         'role-delete',
         'product-list',
         'product-create',
         'product-edit',
         'product-delete'
      ];


      foreach ($permissions as $permission) {
           Permission::create(['name' => $permission]);
      }
  }
}

I can give you more code if you wish from the project.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Hristian Yordanov
  • 650
  • 1
  • 6
  • 25
  • Can you tell any roll associated with any permission and how you are associating those role to user? – Prafulla Kumar Sahu Mar 15 '19 at 14:22
  • the permissions I think are in the `roles` page that doesn't have access – Hristian Yordanov Mar 15 '19 at 14:26
  • your user should be associated with some role and the roles are associated with some permission, right? – Prafulla Kumar Sahu Mar 15 '19 at 14:27
  • Yes. But in the tutorial, there is no user associated whit any permission. I need to manually add permission to role in to the database – Hristian Yordanov Mar 15 '19 at 14:43
  • I think, either user should be associated with some role which has the permission to access that page or user should be associated with some permission to access that page, if not how you will be do that operation, Is the login user is associated like this and you are not able to do this? I do not have a large experience in spati, but just tried with a fresh installation, I think I can use it somewhere. You can check it [here](https://github.com/PrafullaKumarSahu/spatidemo) – Prafulla Kumar Sahu Mar 15 '19 at 14:57
  • In the tutorial you mentioned, have you followed step 9 correctly? – Prafulla Kumar Sahu Mar 15 '19 at 14:59
  • Yes, I did. In fact, now I see in the beginning of the tutorial it says: `After register user, you don't have any roles, so you can edit your details and assign admin role to you from User Management.` But there is no `admin` role... :) – Hristian Yordanov Mar 15 '19 at 15:07
  • what are the role you have? – Prafulla Kumar Sahu Mar 15 '19 at 15:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190098/discussion-between-prafulla-kumar-sahu-and-hristian-yordanov). – Prafulla Kumar Sahu Mar 15 '19 at 15:21
  • Also would like to know, if you are getting this error for new product creation or new user creation? – Prafulla Kumar Sahu Mar 15 '19 at 15:24

1 Answers1

0

I created a repository I mentioned in comment to setup same thing as the tutorial you mentioned. What I need to do was, I created a role with create-product permission and assign that to one user and from that user credential I could create new product.

so, in tutorial he has skipped two steps, role creation and assigning role to user before creating product.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
  • Can you tell me how you created it(the role)? – Hristian Yordanov Mar 18 '19 at 07:06
  • @HristianYordanov from artisan you can create new permission as in `roles/create`, you will be having no access, then assign that role to one user and now if you want to create new role to allow user to create a product you can do it, or simply as you will be having writer role with permission `edit articles`, just add this permission to `RoleController __construct` permission for adding new role or even in `ProductController __construct` . – Prafulla Kumar Sahu Mar 18 '19 at 07:12