Customize Laravel Auth Redirect: From Login to Register

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys today I want to show you how to customize the default auth redirect what do I mean by that so for example if you have a logged in user and you want to show some URL only for that user here's laravel Breeze example so for example dashboard is accessible only after you log in what happens if we log out and try to access that dashboard URL for example I found that URL somewhere online on Twitter or wherever I click that and I land on login page but wait I don't have any credentials to log in with yet I don't have a user so then I need to go back to the home page and where is that home page then I need to click register so additional steps maybe it would be logical if the person is not logged in to redirect to register not log in how to customize that actually it's pretty easy to understand that we need to know where that middleware auth comes from and auth is just a name for the middleware and all the middlewares are registered in the file app HTTP kernel in laravel and there is a list of route middlewares and auth is just a name for this class and do you notice one difference in all those lists of laravel middlewares there are three middlewares that are different from the other ones I will give you a second to think the answer is three of them don't come from the vendor meaning we can customize them easily so C illuminate auth illuminate session illuminate everything is from Bender so there are one two three four five seven middlewares which we cannot easily change it is still possible but then we need to create class override them and something like that but those that come from App HTTP middleware those are accessible and we can do whatever so for example oauth is actually in the public app HTTP middleware so if I click here in phpstorm look at that there is a specific method redirect to waiting for us to customize it so it is as easy as changing the route login to Route register which exists in my larval breeze so now if I go and paste the URL of the dashboard I automatically get redirected to the register and actually here you can customize it to whatever you want return route not only login or register but specific error page or whatever you want it's all in app HTTP middleware authenticate class so that's it a short laravel tip if you want more lateral tips like this one I have a separate repository of laraveld reliable tips with more than 300 tips by topic so I will link that in the description below and you can browse around those and find out something new for yourself that's it for this time and see you guys in other videos
Info
Channel: Laravel Daily
Views: 11,981
Rating: undefined out of 5
Keywords:
Id: ViPKjV8NQy4
Channel Id: undefined
Length: 2min 42sec (162 seconds)
Published: Mon Dec 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.