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 :
• Video
Admin And User Login :(Multi Auth - Guards )
• Laravel Admin And User...
Our Playlist:
Computer Facts: • Computer facts
Laravel User Management System :
• Laravel User Managemen...
Laravel Auth System :
• Laravel Multi Auth System
Laravel And Vuejs
• Laravel And Vuejs
Laravel Eloquent Relationships
• Laravel Eloquent Relat...
GitHub Link :
github.com/aja...
#GatesVsPolicies #MiddlewareVsGuards #LaravelCoreConcepts
Please subscribe to my channel and share the video with your friends.
11 сен 2024