Questions tagged authorization

Explore the latest questions and answers asked by our top developers.

Laravel keeps passing GenericUser to Policies instead of my User Model

I am trying to use the standard Laravel auth related functionality. I have the standard login, register, logout, etc… working fine. But my problem is that whenever I go to use functions like Auth::user() this is returning the GenericUser model rather than my own App/Models/User.php model. The problem is that my User’s model has some […]

How do you set a default policy in Laravel Nova?

Following this, everything works great: However, for better security practices, I’d like to have it so that if no policy is set, a Nova resource will default to my ReadOnlyPolicy.php. Currently, if no policy is set, Nova sets all permissions to true which seems like a bad idea in case a future dev creates […]

By Citizen
Categorised as authorization, laravel, laravel-8, php, policy Tagged , , , ,

I have a laravel API project about store of products

in my app , user’s have to signup and login then they can add ,update or delete products . now i have created CRUD function in Product Controller and signup/login function in another one . then i have made routes in API file (look at the photo)routes the problem is that when i try to […]

By sarah ka
Categorised as api, authorization, laravel, postman, token Tagged , , , ,

create a role user model for each spatie laravel-permission Role assigned to a User

I am building an LMS application in laravel. I’ve got a user model and I use spatie/laravel-permission to assign roles/permissions. Suppose I have admin, teacher, tutor, student roles with permissions assigned to each role. A logged in user can have multiple roles, for example a user can have a teacher role AND a tutor role. […]

By Suhaib Ahmad
Categorised as authorization, laravel, model, roles Tagged , , ,

How to access model instance in a Request class in Laravel 8?

In my Laravel project I want to authorize user via a Request like this: <?php namespace DomainContentsHttpRequestsBlog; use DomainContentsModelsBlogPost; use IlluminateFoundationHttpFormRequest; use IlluminateSupportFacadesGate; class ReadPostRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if (request(‘id’) !== null) { abort(403); […]

Authorization and php

I created the custom basic auth in laravel. But, whenever I try to authenticate, there’s a 400 bad request error. Authorization header comes out well like "basic base_encode64 (username: password)" If I exclude that header, 401 error comes out as I intended from the code I made… If I put in the Authorization header, I […]

Managing permissions in a large Laravel project using Exceptions?

I’m working on a big Laravel project that has 5 user types, around 50 models and the same amount of controllers. Each user type has their own permissions calculated from a separate table based on different factors, so a simple model policy won’t work. What I have done so far, is to create a policy […]

By Jack Johansson
Categorised as authorization, laravel, php Tagged , ,

Delete Post Authorize Laravel API

I want delete a post with authorization but failed with error "message": false, "errors": "This action is unauthorized." destroy controller public function destroy($id, Post $post) { try { $this->authorize(‘delete’, $post); $posts = Post::find($id); $posts->delete(); return response()->json([ ‘success’ => true, ‘message’ => ‘Success’ ]); } catch (Exception $e) { return response()->json([ ‘message’ => false, ‘errors’ => […]

By raihan
Categorised as api, authorization, laravel, php, policy Tagged , , , ,

Validation vs Authorization

I use Laravel for my project however my question is a general question. I have a form which has two limitations for the number of submissions. per user limit and overall limit. If a user tries to submit a form which violates one of the limitations, system would prevent form submissions. My question is related […]

By S kh
Categorised as authorization, laravel, validation Tagged , ,

Is there a way I can set user authorization on my website using laravel?

I’m working on the website and, one of the things I want to do is put authorizations on some of the features on the website so that some authorized users can use them and others can see them, but they can’t only use them without authorization. For example, User A can see features 1, 2, […]

By randomman
Categorised as authorization, laravel Tagged ,
1 2 3 6

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us