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

207 questions
175
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
  • 4,939
  • 4
  • 13
  • 27
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,025
  • 1
  • 8
  • 26
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,324
  • 4
  • 18
  • 35
9
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
  • 8,971
  • 23
  • 105
  • 242
8
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…
7
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
  • 1,915
  • 3
  • 17
  • 37
6
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…
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
  • 760
  • 1
  • 12
  • 41
5
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
  • 705
  • 7
  • 23
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…
4
votes
0 answers

Multi auth API token laravel 5.4

I want to create Multi auth that have two parts (user and pemandu_bas). but when i tested POST 'pemandu_bas' token to postman, my 'pemandu_bas' is doesn't works as api. It keep show error like this .This is my config/auth.php 'guards' => [ …
4
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,346
  • 2
  • 14
  • 31
4
votes
1 answer

Subdomains and Auth with laravel

I am created a project which has multiple different sections all stored within a subdomain for example: core.sample.com map.sample.com character.sample.com I want the user to only be able to login at: sample.com and see a page to select which…
4
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
  • 34,200
  • 85
  • 240
  • 456
4
votes
1 answer

Laravel Auth modify for two kinds of users

I'm currently trying to modify the laravel Auth two be able to register two different kinds of users, a seller and a buyer. Both have the same form, except one field, that only the seller has, called companyName. So what I did is putting a dropdown…
nameless
  • 1,277
  • 3
  • 23
  • 67
1
2 3
13 14