Questions tagged [laravel-authorization]

Laravel Authorization is the service provided by the framework for authorization methodology. It provides them using Gates and Policies.

Laravel also provides a simple way to organize authorization logic and control access to resources. There are a variety of methods and helpers to assist you in organizing your authorization logic.

Gates are similar to routes and Policies we can think of like Controllers.

Gates are Closures that determine if a user is authorized to perform a given action and are typically defined in the App\Providers\AuthServiceProvider class using the Gate facade.

Policies are classes that organize authorization logic around a particular model or resource. For example, if your application is a blog, you may have a Post model and a corresponding PostPolicy to authorize user actions such as creating or updating posts.

We can generate policy using the below artisan command :

php artisan make:policy PostPolicy --model=Post

Reference :

https://laravel.com/docs/5.8/authorization

226 questions
178
votes
3 answers

Can Anyone Explain Laravel 5.2 Multi Auth with Example

I am trying to authenticate users and admin form user table and admin table respectively. I am using the User model as provided by laravel out of the box and created the same for Admin. I have added a guard key and provider key into auth.php.…
imrealashu
  • 5,089
  • 4
  • 16
  • 28
13
votes
2 answers

Laravel 5.3 Password Broker Customization

Does anyone know how to override the functions used within laravel's password broker? I know the docs: https://laravel.com/docs/5.3/passwords#resetting-views Give information on what to do for things like views and a few surface level things but…
Andre F.
  • 1,123
  • 1
  • 10
  • 27
13
votes
8 answers

Laravel 5.2: Auth::logout() is not working

I'm building a very simple app in Laravel 5.2, but when using AuthController's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check() and it doesn't change after calling the log out action. I have this route…
Felipe Peña
  • 2,712
  • 4
  • 22
  • 41
11
votes
2 answers

Can authorize method in Request class return customized message for HandlesAuthorization trait?

I have the following code in Request class to check if the user is authorized to perform update. HandlesAuthorization trait, by default gives default message. Is there any way to return customized message? I saw the authorize method in Request…
Pankaj
  • 9,749
  • 32
  • 139
  • 283
11
votes
4 answers

How laravel `Auth:user()` or `Auth:id()` works

How laravel Auth:user() or Auth:id() works Is it resides in session or database. I searched but not get good article. Please help to understand. I know I will get many down-votes ;)
GRESPL Nagpur
  • 2,048
  • 3
  • 20
  • 40
9
votes
2 answers

Changing Laravel auth table name and column names

I want to change the table name and some column names of laravel auth table. Change table name from 'users' to 'accounts' Change table column name from 'name' to 'username' Change table column name from 'email' to 'email_addr' Change table column…
9
votes
2 answers

How to handle roles/permissions in an SPA (Laravel+Vue)

I have been hearing a lot of buzz about SPAs, so I thought let's give it a shot and I started working on an SPA project with Laravel+Vue. I started with making some CRUDs with the help of axios and vue-router. Everything worked out great, until I…
8
votes
2 answers

Customize Laravel FormRequest autorize method validation

Laravel allows us to authorize, or not, a FormRequest to be processed via the authorize method. If the request isn't authorized, it will throw a \Illuminate\Auth\Access\AuthorizationException exception, with a message: This action is…
Gabriel Caruso
  • 789
  • 1
  • 7
  • 17
7
votes
1 answer

Laravel Change Password Reset Token duration for specific tokens

In my application, user's will have their accounts created for them by other people, so I want to send a password reset email to them so they can set their password and log in. The problem is I don't want these links to expire after 60 minutes like…
Matthew Weeks
  • 920
  • 9
  • 30
6
votes
2 answers

Laravel - Refactoring User Permission "Gate::Define" Code Into Easier to Read Code

So what i'm basically trying to do is refactor my long bit of code to something more simpler. I found this snippet of code at this website and I don't really understand what's going on inside the code. I don't think that this snippet of code will…
J. Robinson
  • 931
  • 4
  • 17
  • 45
5
votes
1 answer

Policies with extra parameters

I know, how to use Laravel policies and everything works, but I am stuck with create(...) method. My app is a training diary for ski racers. Each racer can manage (view, add, edit..) his own diary. Each trainer can manage his own diary, diary of…
Arxeiss
  • 976
  • 16
  • 34
5
votes
2 answers

How to define or pass auth guard for broadcast authentication routes instead of default auth guard?

I am very new to realtime event broadcasting, I have simple laravel-echo-server setup and working with everything. I am unable to set/define authentication against other auth guard it is always checking with user/default guard defined in auth.php I…
msonowal
  • 1,553
  • 3
  • 17
  • 36
5
votes
1 answer

Can I override the AuthenticatesUsers login() method to implement a custom login involving a call to a REST web service in this Laravel application?

I am new to PHP and Laravel and I have the following problem. I know that Laravel provides an ready-to-use login system, created using the statement: php artisan make:auth The problem is that this system directly interacts with the database. My…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
5
votes
1 answer

How to understand Laravel framework completely?

I have gone through Laravel beginners tutorial, and now I can understand every topics listed in those tutorials and have created my own project, but as I saw in those, the tutors were able to understand what each file was meant for and had the…
rranj
  • 288
  • 1
  • 5
  • 16
4
votes
2 answers

Laravel passport refresh token

I am using a Laravel version 5.5 using Passport for authentication. I have successfully create the token and can access it using the auth:api middleware. But whenever user login into system it create new token for that user. I just want to refresh…
1
2 3
15 16