Laravel Gates Policies Middleware And Guards | Laravel Core Concepts | Laravel Basics | Ajay Yadav
In this video Understand Laravel Gates Policies Middleware And Guards in detail, Laravel basic and Laravel Core Concepts. And When And How Use Laravel Gates Policies Middleware And Guards.
Middleware:
Typically runs on a route (but you can also run it on controller methods) and can be used to filter or inspect incoming requests.
One example would be auth, which determines if the person trying to request a particular route is authenticated (logged in) to the system. Another example would be to check that a request has a specific header (e.g. if you want to check that the app is sending a X-MYAPP-CUSTOMHEADER header or something)
As mentioned, middleware can be defined on a route (e.g. in web.php or api.php) or in a controller.
Gates:
Gates are functions defined in your AuthServiceProvider.php file (in the App\Providers folder) and specify what a user is allowed to do and what they're not allowed to do.
Policies:
Policies work similarly to gates, but just apply to a specific model and are stored in their own file (in App\Policies)
You can create one by using php artisan make:policy PostPolicy -m Post. It'll create a file called PostPolicy.php which will create a bunch of functions:
viewAny // Can the user even look at this model? If no, they'll be denied for all the below methods
view // Can the user look at the specified Post?
create // Can they create a new Post
update // Can they edit / update the specified Post?
delete // Can they (soft) delete the specified Post?
restore // Can they restore the specified (soft) deleted Post?
forceDelete // Can they force delete the specified Post?
Guards:
Guards are a way to specify how users are authenticated for requests. They're the definition of how the system should store and retrieve information about your users.
You can find the configuration in your config/auth.php file. A web guard is the traditional cookie store - so that web guard instructs Laravel to store and retrieve session information the classic way. The API guard, on the other hand, uses tokens. So you would use the API guard if you want to authenticate users and requests using an API token in the header (bearer) or query parameter.
Gates and Plicies video :
https://www.youtube.com/watch?v=HPLBDrrzZcU
Admin And User Login :(Multi Auth - Guards )
https://www.youtube.com/watch?v=UWniysfpTmM
Our Playlist:
Computer Facts:https://www.youtube.com/playlist?list=PLT51dtioU1pMRgv8kNYajmgJfA1W1zwqv
Laravel User Management System :
https://www.youtube.com/playlist?list=PLT51dtioU1pPNxwwo3dWfkUCKI2BXnc_H
Laravel Auth System :
https://www.youtube.com/playlist?list=PLT51dtioU1pPmtFnYQ5WRnYvvL1zW74wl
Laravel And Vuejs
https://www.youtube.com/playlist?list=PLT51dtioU1pN0mQqQ5RM5nE8uOfzsqml2
Laravel Eloquent Relationships
https://www.youtube.com/playlist?list=PLT51dtioU1pO7YgLOyNY0KF_3ny79D0BV
GitHub Link :
https://github.com/ajayyadavexpo/InertiaTodo
#GatesVsPolicies #MiddlewareVsGuards #LaravelCoreConcepts
Please subscribe to my channel and share the video with your friends.