2

I have recently started using laravel 5.2. I don't understand what's the use of guards. As I see everything that can be done with guard can easily be replaced with lot more readable middleware. Am I missing anything ?

1
  • 1
    You might want to specify why you believe it would be more readable to move the code to a middleware and include a concrete example, so we can understand exactly what you're point of view is. Commented Apr 9, 2016 at 17:23

2 Answers 2

1

Guard will let you to have multi authentication in your app and you we have diffrent provider even drivers(such as doctrine or eloquent). for example, you can have login with user model and an admin model in one application at the same time.

Sign up to request clarification or add additional context in comments.

Comments

1

You may specify which guard instance you would like to utilize using the guard method on the Auth facade. This allows you to manage authentication for separate parts of your application using entirely separate authenticatable models or user tables.

The guard name passed to the guard method should correspond to one of the guards configured in your auth.php configuration file:

if (Auth::guard('admin')->attempt($credentials)) {
//
}

Know more about Illuminate/Contracts/Auth/Guard

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.