3 Different Ways To Get Authenticated User In Laravel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to Lara tips one of the developers who had just joined in my office asked how we can get the authenticated user in our laravel application and I told him we can get the authenticated user by two ways but there is a third option which I use and I'll also show you that one so let me show you all these options over here okay here currently I am here in the project and here this one whenever I go to adbit dashboard it will reach over here now in order to get the authenticated user and I'm already authenticated and auts and there is this auth method helper method available in arrival on which we can call user like this and then we will get the currently authenticated user I am already authenticated over here so if I reload over here then you can see here I am getting this user okay the admin user since I am logged in as admin I am getting this admin now there is also another way so here we can also do auth like this and let me import this auth which is this support facade and here also you can call user like this and again if I come here and refresh the space then we'll get the same thing because both of these will give us the authenticated user but if you see here if I go here in the user then you can see here I have this sort name this is super admin so many other methods on the user model as well but using these method we cannot call those you can see here we are only getting these methods over here and in this auth user also we are only getting these things so for that I have third option I have created helpers.php inside the app folder if you see here this app and inside here we have this helpers.php and now here let us create a method called auth user you can see here I am creating this auth user method and I am just returning this authenticated user which I have used over here the same thing but here I have returned this either it will give us the user model or null so now here if I just do here let's say auth user like this you can see here it will auto complete for us and here I'll comment this and here now if I just do it like this then we'll get all the methods available in the user model okay so here if I just write here sort name then you can see here the sort name is auto completed for us and for these two work we also need to do one more thing here we have to go here in the composer.json file and inside this Auto load we have to add one more thing which is this so we have to write here files and here app slash helpers the path of this helpers.php class over here so after this we have to do composer dump Auto load and run it but I have already done it so I don't have to do it so after that you can access this Earth user method over here otherwise it will throw error after this you can see here this admin the name is admin then we must get only a in the sort name so if I reload then you can see here we are getting a over here so I hope you enjoyed this video guys and this video is sponsored by cloudways and please don't forget to check out cloudways and now I would like you to introduce to this video sponsor which is is cloudways cloudways is a managed Cloud hosting platform which focuses on your business and avoid all the web hosting hassles cloudways will take care of the server setup for you and you can go live in minutes using the cloudways you can select any one of these applications like WordPress laravel PSP Etc and you can host those in any one of This Server Like digitalocean AWS volts or Google cloud or linode and also you can scale your server size as you need using the simple and easy user interface you can use the link below to subscribe to cloudways and if you do so you'll get 15 as a credit and you can use that 15 to set up a base server and it will last you almost a month which means that you are getting one month free so thank you for watching have a great day bye
Info
Channel: Laratips
Views: 9,747
Rating: undefined out of 5
Keywords: laravel for beginner, laravel beginner tutorial, laravel tutorial for beginners, laravel tutorial, laravel advanced, laravel advanced tutorial, laravel 8 advanced tutorial, php, php tips, php tips and tricks, tips and tricks, laratips, laravel, laravel tips, laravel 9 tutorial, laravel 9 advanced, laravel 9, laravel 9 advanced tutorial
Id: FuiR3GTjIH8
Channel Id: undefined
Length: 4min 6sec (246 seconds)
Published: Fri Jun 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.