Questions tagged [laravel-permission]

Laravel permission is a 3rd party Laravel package developed by Spatie to manage user permissions and roles in a database.

Laravel permission is a 3rd party Laravel package to manage user permissions and roles in a database.

It is maintained by Spatie, a Belgian company that creates websites and web application. This is one of many Laravel packages they maintain.

It can be installed using composer via the following command:

composer require spatie/laravel-permission

Links:

261 questions
16
votes
5 answers

The given role or permission should use guard `` instead of `web`. -Laravel

I am using a package spatie for user roles and permission. When creating and assigning a role to user, i get the error The given role or permission should use guard `` instead of web Below is how i save my data in the controller What could be…
Switz
  • 453
  • 1
  • 7
  • 21
14
votes
11 answers

spatie/laravel-permission There is no permission named `edit_project` for guard `api`

I am using Laravel 5.6 with spatie/laravel-permission version 2.9 also using Laravel Passport as auth driver with $guard = 'api'. When I am trying to assign an array of permission like ['edit_project', 'add_project' 'delete_project'] to a role with…
Barakzai
  • 351
  • 1
  • 3
  • 10
7
votes
2 answers

How to integrate Spatie's laravel-permission with JetStream properly?

I have a nicely working basic install of Laravel JetStream and Spatie's laravel-permission in Laravel 8. I can assign a role to the user during registration via $user->assignRole('visitor'); return $user; and can restrict the available menu items…
7
votes
1 answer

Enabling certain roles to access Laravel Nova dashboard?

I have the Spatie Permissions package installed, and I have created policies to restrict access for my models using this package. However, I'm struggling a bit on the creating a gate to enable certain roles such as 'Admin' and 'Content Editor' to…
Adnan
  • 3,129
  • 6
  • 31
  • 36
7
votes
4 answers

Laravel spatie/laravel-permissions Naming Conventions

Are there some naming guidelines I should be following when it comes to naming permissions? Right now, everything I find is just along the lines of "Add Foo","Edit Foo","Delete Foo","Add FooBar","Edit FooBar","Delete FooBar", and so forth and so…
5
votes
2 answers

How can use Spatie add assign role to all users using seeder in laravel?

I am using Spatie role-permission for handling user roles in an laravel application. I had created users using factory factory(App\User::class, 50)->create(); and now some of the users are admin roles. I want to replace all role to supscriber and…
Syam kumar KK
  • 524
  • 2
  • 6
  • 32
5
votes
3 answers

List users not belongs to a role

I use laravel spatie package for user permissions. I need to list all users not belongs to a specific user. For example list all non admin(role) users. For listing all admin users I used $users = App\User::role('admin'); I need just opposite to…
Haris
  • 126
  • 3
  • 11
4
votes
0 answers

In Facade.php line 258: A facade root has not been set

I was working on my Laravel project and suddenly got this error: In Facade.php line 258: A facade root has not been set. My last command is php artisan make:migration ... It ran successfully Here is the file causing the…
4
votes
2 answers

Laravel spatie assign role to user not working

I am simply doing what is in the documentation but God knows what the issue is. I have put use HasRoles; in my User Model use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable implements JWTSubject { use HasRoles; } but…
Maha Waqar
  • 585
  • 1
  • 10
  • 24
4
votes
3 answers

BadMethodCallException Call to undefined method App\Models\User::hasAnyRole()

I'm using Laravel-Permissions and wrote in rotes\web.php: Route::group(['middleware' => ['role:admin']], function () { Route::get('/admin', function () { return "Test"; }); }); I added in app\Http\Kernel.php : protected…
Andrew Stetsko
  • 87
  • 1
  • 1
  • 9
4
votes
3 answers

Laravel Eloquent - pluck() role name

I'm trying to get the authenticated user object from the request with roles. I'm using Spatie laravel-permissions and Laravel 8. Getting User object from request like so $request->user()->getRoleNames()->pluck('name'); return…
Josh Bonnick
  • 2,281
  • 1
  • 10
  • 21
4
votes
0 answers

Laravel Spatie Permission for Multi Tenant

Laravel version:7.16, Spatie/laravel-permission version:3.13 I am creating kind of multi tenant application. All tables will have company_id. users table also gets company_id. I followed these…
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
4
votes
3 answers

Spatie\Permission\Exceptions\PermissionAlreadyExists : A `edit listing` permission already exists for guard `web`

I have cloned marketplace repo and did the appropriate configurations. When I use php artisan db:seed i get this error david@david-Lenovo-G50-30:~/projects/marketplacekit$ php artisan db:seed Seeding: UsersTableSeeder Seeding:…
davidkihara
  • 493
  • 1
  • 10
  • 30
4
votes
1 answer

Laravel Spatie Get All Permissions with Eager Loading

everybody! I am using Laravel Spatie Permission Package. And I can get user's all assigned permissions like this. $user->getAllPermissions() However, I want to get all permissions with eager loading. Maybe like this. $users =…
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
4
votes
6 answers

There is no role named `admin`. laravel

i use this package : https://github.com/spatie/laravel-permission/tree/v2 code : $user=User::find(2); $user->assignRole('admin'); and when i assign admin role to user I'm dealing with this error There is no role named…
ali dehqani
  • 164
  • 1
  • 3
  • 18
1
2 3
17 18