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
2
votes
3 answers

Give multiple permissions to a role - Spatie

How can we assign multiple permissions to a single role at once? $permission1 = Permission::create(['name' => 'Create Client']); $permission2 = Permission::create(['name' => 'View Invoice']); $permission3 = Permission::create(['name' =>…
shavindip
  • 607
  • 9
  • 27
2
votes
1 answer

(1/1) FatalErrorException Call to a member function hasPermissionTo() on null in ClearanceMiddleware.php line 17

https://scotch.io/tutorials/user-authorization-in-laravel-54-with-spatie-laravel-permission. I have followed the above link for my reference to set roles and permissions to users. I am getting the error: (1/1) FatalErrorException Call to a member…
Raffi
  • 31
  • 1
  • 5
1
vote
1 answer

Permissions relation loaded but not returned with DTO [ Laravel/Spatie-permissions/Spatie-data ]

I've started laravel two months ago and I work to project. I have problem that I don't understand. All my others DTO works but not them have relation with Spatie permissions. My problems are that I have undefined PermissionsData's collection after…
WantyJF
  • 29
  • 4
1
vote
1 answer

Laravel 9 : wrong roles (spatie/laravel-permission)

I use Laravel 9, breeze and the package spatie/laravel-permission and I made some modifications to be able to assign a role after the authentification: (I check the number in the column "id_role" from my table User to known the role…
1
vote
3 answers

spatie / laravel-permission can return always true

when using laravel spatie permissions every thing is ok when creating permissions , roles , assign roles to users. but when using $this->authorize('View Country') OR $user->can('View Country') always return true. i am using laravel v9.0 and…
hossamGamal
  • 161
  • 1
  • 10
1
vote
2 answers

Laravel appended attribute returns null when model is initiated through dependecy injection

I have an appended attribute that works when I do Model::first()->appended_attribute, but when get the model object instantiated through laravel's route dependency injection like below : public function update(UserRequest $request, User $user) { …
1
vote
1 answer

Laravel Spatie can() always returning false but hasPermissionTo() works

I'm trying to create permissions and roles for users in a Laravel Project using Spatie creating permissions and assigning them to roles and then users works fine, but when checking for permission using can it always returns false even when the…
Freek
  • 65
  • 8
1
vote
0 answers

Laravel Spatie permissions best way to add multiple roles to check against user roles for multiple models

I'm working inside a Laravel 10 project that uses the Laravel Spatie Permissions package v5.9.1. My Laravel project is used as an API that outputs stuff to a Nuxt JS front-end, including a menu. Super admins of my platform can create a menu, and…
Ryan H
  • 2,620
  • 4
  • 37
  • 109
1
vote
1 answer

Laravel Spatie permissions how to define set of permission for each user based upon role?

I have 4 types of users using my system, 1. superadmin 2. superadmin team, 3. admin and 4th. admin team members, as I'm using spatie for roles and permissions, I have set of modules (permissions)which are common for all types of users and there is…
wiki
  • 13
  • 4
1
vote
1 answer

Spatie assignRole not working (Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsTo::sync())

Spatie user role permissions not working Here is my RoleController.php use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Permission; public function saveUserRoles(Request $request) { $validator =…
Sambhu M R
  • 297
  • 5
  • 23
1
vote
2 answers

Laravel permission on same resource for multiple roles (Spatie)

I need to grant access to users with different roles to actions of one resource. I tried the following but no luck in web.php routes file: Route::resource('trampas', 'TrampaController')->middleware('role:Administrador|Supervisor'); //Access to all…
1
vote
1 answer

How to give permission to guard using Spatie

I am new to Laravel and I am having modify an existing Laravel application to only give some permission to a guard. When I use the command php artisan permission:show, I see the following: Guard: admin …
Noor
  • 19,638
  • 38
  • 136
  • 254
1
vote
3 answers

How you can use 2 roles on 1 route?

Please tell me how you can use 2 roles on 1 route. I am using the Laravel Permission. Routes Route::group(['middleware' => ['role:user_сitisen']], function () { Route::get('/addcitisens', [App\Http\Controllers\CitisenControl::class, 'index']); …
1
vote
1 answer

Laravel Spatie Permission does not redirect not authorized user to login page

I am using spatie/laravel-permission, When not authorized users view private page, laravel shows 403 error but I want laravel redirects them to login page and after login automatically redirect to private page. For example not authorized user wants…
Nobody
  • 11
  • 3
1
vote
1 answer

How to implement hierarchical RBAC in laravel

I already checked the Laravel-permission by Spatie but I can not find a native way to implement the concept of parent role which inherent child role permissions. I was using such concept in Yii2 but I can not able o switch such feature to Laravel. I…
Eslam Sameh Ahmed
  • 3,792
  • 2
  • 24
  • 40