What is the main difference between gates and middlewares in laravel?

345 Views Asked by At

people, I just want to ask a very clear question. i know that is the middleware is used to authenticate a user but the gate and policy come to restrict user behavior depending his/her role. I used LARAVEL gates to redirect the user to the login page if he is not authenticated So, the question is: Does LARAVEL middleware contains Gates in it or what ?? Thanks advanced.

1

There are 1 best solutions below

0
On

Gates

Gates are basically used to check that a user is authorized to perform a given action.

Middleware

Middleware provide a way for inspecting and filtering HTTP requests which are entering in your application. For example: Laravel includes a middleware that verifies that the user of your application is authenticated. and you can define your own middleware.