Authorization in Laravel: Can You Do That?

  Рет қаралды 6,533

Laravel

Laravel

21 күн бұрын

There's another "auth" that Laravel makes incredibly easy out of the box: authorization. But just how is authentication and authorization different?
Let's take a look at Gates and Policies, when to use one over the other, and the basics of how you can check if a user is authorized to do something anywhere in your application.
**clarification: while you can use $this authorize() in a Livewire class, you will need to use Gate authorize() in a controller in Laravel 11
*note: there's a LOT of awesome helper functions and ways to check gates and policies that we didn't talk about. The docs are a great place to dive deeper.
Authorization Docs: laravel.com/docs/11.x/authori...

Пікірлер: 41
19 күн бұрын
I really love how we can say "actually there is something for that in Laravel" for almost anything a modern Web application needs. I'm using Laravel since version 3 and love every minute spent using it. Thank you all the developers and users making it better each day
@LaravelPHP
@LaravelPHP 19 күн бұрын
Same here. It's easy to make beautiful applications. :) -Josh
@marekbee
@marekbee 19 күн бұрын
I am VIP -> very into PHP 🙌
@LaravelPHP
@LaravelPHP 19 күн бұрын
😏
@habibullahiM
@habibullahiM 19 күн бұрын
@@LaravelPHP I just started with laravel and was wondering how he setup vscode and laravel
@reactoranime
@reactoranime 18 күн бұрын
Would be nice to see some demos with: multiple user roles and separate role capabilities, and as an extra custom user capabilities. This definetely requires some tables like roles, capabilities and role_capabilities and user_capabilities.. but would be nice to see such implementation
@LaravelPHP
@LaravelPHP 13 күн бұрын
That's good to know. It might be a good option for a separate video. Looking into how Laravel Jetstream uses these roles and permissions is a great start. :) -Josh
@kamleshpaul414
@kamleshpaul414 19 күн бұрын
great explanation 🎉
@LaravelPHP
@LaravelPHP 13 күн бұрын
Thank you. I'm glad it helped. :) -Josh
@sandeepbhambre
@sandeepbhambre 19 күн бұрын
I think In laravel 11 projects, $this->authorize() would not work by default because the base controller doesn't have supporting traits.
@LaravelPHP
@LaravelPHP 19 күн бұрын
Hey! You are correct. Great point. I should have clarified that the $this->authorize can work in a Livewire class but you'll use Gate::authorize in a controller. I'll add this clarification to the description. :) -Josh
@Lopoi
@Lopoi 19 күн бұрын
Sometimes it`s nice to see a video like this to remind me of features of laravel that I forget exist
@LaravelPHP
@LaravelPHP 13 күн бұрын
I love that. I forget about neat little helper functions and directives ALL the time. I'm glad we could help remind you of things. :) -Josh
@shubhamsahuSD
@shubhamsahuSD 16 күн бұрын
I am starting to like yours this type of videos ❤
@LaravelPHP
@LaravelPHP 13 күн бұрын
Well thank you. I'll try my best to keep it going. :) -Josh
@sigmund233
@sigmund233 13 күн бұрын
What's your opinion on using something like spatie/laravel-permission? It is my go to since I prefer role/permissions than Gates or Policies
@LaravelPHP
@LaravelPHP 13 күн бұрын
I think that's a great way to build on top of what Laravel already offers, especially if you have unique or specific use-cases. But USUALLY, a package like laravel-permission is going to be used in conjunction with policies in any application. So it's helpful to know both. :) -Josh
@safalpiya2903
@safalpiya2903 19 күн бұрын
Thanks for the great content! By the way I'm using laravel as API with a React SPA without Inertia. What would be a good way to check if a user is authorized to do something inside the react app similar to @can('alert-users' ) directive inside blade files?
@iapv
@iapv 19 күн бұрын
Are you using sanctum? If you are, do exactly as the video says except return a json response instead of Inertia::render(). In the frontend, you can fetch the json data as can["alert-user"]. Of course, make sure the user authenticated first. One of the tricky parts of sanctum is setting it up to validate csrfTokens. But there are tutorials for that if you're interested.
@LaravelPHP
@LaravelPHP 13 күн бұрын
Just like @iapv mentioned, you would have to pass that "can" prop when fetching the user on the initial API request. Checking out how this happens in the NextJS Breeze implementation is a good start. -Josh
@vic_casanas
@vic_casanas 19 күн бұрын
Love your videos man 🤩
@LaravelPHP
@LaravelPHP 19 күн бұрын
Thanks so much Vic. I appreciate it. :) -Josh
@srhanzd3022
@srhanzd3022 19 күн бұрын
Thank you man ❤❤❤
@LaravelPHP
@LaravelPHP 13 күн бұрын
Thank YOU. -Josh
@ifeanyinnaemego
@ifeanyinnaemego 19 күн бұрын
I hope am making the best career choice by sticking with Laravel
@LaravelPHP
@LaravelPHP 19 күн бұрын
We think so. ☺️ -Josh
@ifeanyinnaemego
@ifeanyinnaemego 19 күн бұрын
@@LaravelPHP appreciate it
@EMMA-0310zz
@EMMA-0310zz 16 күн бұрын
Can the future of laravel compete with NodeJS and .NET
@LaravelPHP
@LaravelPHP 13 күн бұрын
We think so. But we are pretty biased. 😉 -Josh
@srhanzd3022
@srhanzd3022 19 күн бұрын
Love laravel
@LaravelPHP
@LaravelPHP 13 күн бұрын
Don't tell anybody, but I do too. -Josh
@srhanzd3022
@srhanzd3022 19 күн бұрын
❤❤❤
@LaravelPHP
@LaravelPHP 13 күн бұрын
🥰 -Josh
@yoanestradablanco1608
@yoanestradablanco1608 19 күн бұрын
Greet video
@LaravelPHP
@LaravelPHP 19 күн бұрын
Thank you! :) -Josh
@Pekz00r
@Pekz00r 18 күн бұрын
I don't think you got the the initial explanation of authentication vs authorisation right. In that example authentication would be something like showing your ID to prove that you are you and maybe that you are the actual ticket holder if the tickets are personal. The ticket is authorisation and allows you to enter the venue as well as the specific areas. Great video otherwise.
@LaravelPHP
@LaravelPHP 13 күн бұрын
Probably so! Good catch. It does break down a little bit. 😂 It would probably be less of having tickets and more about proving those tickets are yours, like you said. :) -Josh
@dev22221
@dev22221 19 күн бұрын
Only 3 of these are correct. Find out which.
@user-qd6hj2fn4w
@user-qd6hj2fn4w 13 күн бұрын
Зачем ему кепка нужна? ну ладно очки, это понятно, возможно проблема со зрением, но зачем ему кепка?..
@LaravelPHP
@LaravelPHP 13 күн бұрын
Мне нравится, как это выглядит. Это весело. :) -Josh
@user-qd6hj2fn4w
@user-qd6hj2fn4w 13 күн бұрын
@@LaravelPHP я не хотел тронуть вас, просто стало интересно. У нас в России когда есть нужда, тогда одевают одежду, но чаще даже не одевают, я обычно задаю вопрос в России вопрос, на улице солнце светит, почему без кепки? Или когда на улице мороз, спрашиваю почему без шапки? 😅
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 61 МЛН
The joker's house has been invaded by a pseudo-human#joker #shorts
00:39
Untitled Joker
Рет қаралды 14 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 7 МЛН
Is Laravel Livewire actually secure?
8:19
Josh Cirre
Рет қаралды 6 М.
Let's Make a Scope in Laravel
4:02
Josh Cirre
Рет қаралды 1,2 М.
NextJS and Laravel Can Be Friends
23:54
Laravel
Рет қаралды 17 М.
Encrypt with Prune,  Dispatch without Delay & Prohibitable
5:04
Why You Get More Done with Laravel 🚀
7:42
Laravel
Рет қаралды 8 М.
Enough sed! substitute
0:43
grepliz
Рет қаралды 9
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 8 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 37 МЛН
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,6 МЛН
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 28 МЛН
Что не так с яблоком Apple? #apple #macbook
0:38
Не шарю!
Рет қаралды 130 М.