Category : roles

So currently I’m developing web apps that will have users management and role management (roles using spatie/laravel-permission). it have a lot of roles for example: Root (super admin) Admin Daerah(based on the village) admin unit (based on his working place/unit) Kepala Badan Kepala seksi Staff Citizen Etc. Every user can (and will) have more than ..

Read more

Sorry because my English is weak and I can not speak well!! This is the route I defined on the web.php page : <?php use AppHttpControllersController; use AppHttpControllersGoogleAuthController; use AppHttpControllersProfileController; use AppHttpControllersUrlController; use IlluminateSupportFacadesAuth; use IlluminateSupportFacadesRoute; /* |————————————————————————– | Web Routes |————————————————————————– | | Here is where you can register web routes for your application. ..

Read more

When I’m creating new users and assign them roles and permissions it works fine, but when I assign role using protected route Route::post(‘/excel/upload’, [ExcelController::class,’upload’])->name(‘uploadExcel’)->middleware(‘auth:sanctum’); i get and error: SpatiePermissionExceptionsGuardDoesNotMatch The given role or permission should use guard web instead of sanctum. auth.php ‘defaults’ => [ ‘guard’ => ‘web’, ‘passwords’ => ‘users’, ], ‘guards’ => [ ..

Read more

I have a route : Route::get(‘/TransactionHistory’,’[email protected]’); In Controller QuoteController, I have a function as: public function transactionHistory(){ if(Auth::user()->isAdmin()) { $res= DB::table(‘products_products’) ->select(‘users_users.display_name’,’products_products.name’,’products_products.id’,’products_products.user_id’,’products_products.quantity_type’,’buy_product.price’,’buy_product.rating’,’buy_product.mileage_name’,’buy_product.id as buy_id’) ->join(‘buy_product’,’products_products.id’,’=’,’buy_product.product_id’) ->join(‘users_users’,’buy_product.user_id’,’=’,’users_users.id’) ->get(); } else{ $u_id=auth()->user()->id; $res= DB::table(‘products_products’) ->select(‘products_products.name’,’products_products.id’,’products_products.user_id’,’products_products.quantity_type’,’buy_product.price’,’buy_product.rating’,’buy_product.mileage_name’,’buy_product.id as buy_id’) ->join(‘buy_product’,’products_products.id’,’=’,’buy_product.product_id’) ->where(‘buy_product.user_id’,’=’,$u_id) ->get();} return view(‘templates::pagetwigs/transaction-history’)->with(‘details’,$res); } On routing the path I got error as :Call to a member function isAdmin() ..

Read more

I’m currently working on a laravel project "canteen’. I used a plugin named Spatie to create roles permissions system. This plugin has its own tables from migration like roles, permissions, role_has_permissions, model_has_roles and model_has_permissions. picture example inserting roles to an user I want to make roles Admin, Teacher, Student and Seller. Me as Admin can ..

Read more

Hey I am developing a project where I have roles and permissions for users and I am trying to protect my routes with the help of middleware by defining Gates but it’s showing me 403| Not Authorized. I can’t understand what the actual problem is? Into Category Controller public function addcategory(AdminsRole $adminsroles){ return view(‘add-category’); } ..

Read more

class AuthServiceProvider class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ ‘AppModelsNews’ => ‘AppPoliciesNewsPolicy’, // News::class => NewsPolicy::class, ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); Gate::define(‘news_index’, function ($user) { return ..

Read more

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 actions Route::resource(‘trampas’, ‘TrampaController’)->middleware(‘role:Monitoreador|Coordinador’)->only(‘index’, ‘show’); But when i declare the 2nd line the first in annulled. Same thing happens when it’s declared in the controller’s ..

Read more

I am facing an issue where I have assigned the permission like add , edit , view , delete to items like post and comments which are further assigned to particular roles like admin, user , editor . lets take an example: A admin(role) can perform permissions say add,edit,delete(permission) on particular item say he can ..

Read more

I sent the below value from view to controller: in View: <input type="checkbox" name="Roles[]" value="{{$user->rolesTeams[$i]->pivot}}"/> In Controller: case ‘team-delete’: $input = $request[‘Roles’]; dd($input); Result: array:1 [▼ 0 => "{"user_id":"15","team_id":"2","user_type":"AppUser","role_id":"2"}" ] now How can I make this like: $user = user_id >> which should be 15 $team = team_id >> which whould be 2 $role = ..

Read more

Tell me how you can use 2 roles on 1 route. I am using the Laravel Permission. My routes Route::group([‘middleware’=>[‘role:user_сitisen’]],function(){ Route::get(‘/addcitisens’, [AppHttpControllersCitisenControl::class, ‘index’]); Route::get(‘/citisen/{id}’, [AppHttpControllersCitisenControl::class, ‘show’]); Route::post(‘/citisen/{id}’, [AppHttpControllersCitisenControl::class, ‘update’])->name(‘citisen’); Route::get(‘/destroy/{id}’, [AppHttpControllersCitisenControl::class, ‘destroy’]); Route::post(‘/citisens’, [AppHttpControllersCitisenControl::class, ‘store’]); Route::get(‘/citisens/export’, [AppHttpControllersCitisenControl::class, ‘CitisenExport’]); }); Route::group([‘middleware’=>[‘role:user_avto’]],function(){ Route::get(‘/avtoslist’, [AppHttpControllersAvtosController::class, ‘index’]); Route::get(‘/addavtos’, [AppHttpControllersAvtosController::class, ‘indexAdd’]); Route::post(‘/avtos’, [AppHttpControllersAvtosController::class, ‘store’]); }); Route::group([‘middleware’=>[‘role:admin’]],function(){ Route::get(‘/addcitisens’, [AppHttpControllersCitisenControl::class, ‘index’]); Route::get(‘/citisen/{id}’, ..

Read more

In my application, I’ve used the Sentinel package for authorization. Now I need an API to retrieve user permissions for an expected JSON structure. expected JSON structure: { "user_id": 3172, "first_name": "Bonny", "last_name": "Hewage", "username": "bonny", "user_roles": [ { "id": 2, "slug": "store-user", "name": "Store User", "permissions": {"user.create":true, "user.update":true} }, { "id": 6, "slug": "mu-supervisor", ..

Read more

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 but again and again, getting this error: Call to undefined method IlluminateDatabaseEloquentBuilder::assignRole() Whenever assigning role in seeder: use AppModelsUser; use IlluminateDatabaseSeeder; use SpatiePermissionModelsPermission; use SpatiePermissionModelsRole; public function run() { $role ..

Read more

i’m a laravel beginner and i use laravel-roles from github. I try to do the setup but with the step: php artisan db:seed i get the following error: IlluminateContractsContainerBindingResolutionException Target class [DatabaseSeedersDatabaseSeeder] does not exist. at vendor/laravel/framework/src/Illuminate/Container/Container.php:811 807| 808| try { 809| $reflector = new ReflectionClass($concrete); 810| } catch (ReflectionException $e) { 811| throw new ..

Read more

I am Try to get User List with their role in laravel 8, for role and permission i am use spatie package (https://spatie.be/docs/laravel-permission/v4/) i am trying to get any data via user it return error following function return error $all_users_with_all_their_roles = User::with(‘roles’)->get(); $all_users_with_all_direct_permissions = User::with(‘permissions’)->get(); $user->hasAllRoles(Role::all()); function (https://spatie.be/docs/laravel-permission/v3/basic-usage/basic-usage#eloquent) ERROR : "Call to undefined method AppModelsUser::getAllPermissions()",…} ..

Read more