How to add Custom Route Files in Laravel 8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to our channel in last days we created this laravel 8 multi-guards authentication project but in this video we wrote all routes into a single file which is web.php so today we are going to make custom root files in laravel 8 this is very interesting to learn we are going to create this video because of our friends request for this tutorial i'm not going to create new laravel project but i will use this laravel 8 multi guards authentication project let's get started let's see our roots in web.php file as you can see i wrote all roots inside this single file all normal user admin and doctor modules roots are written here how to make custom root file for each user type for better routes management create custom root file under roots directory and rename to user.php this root file will have all normal user roots now move this user root group to our created user root file and don't forget to add this root facade at the top of user.php file also you have to import user controller on this now we finish our custom root file for normal users create new file and rename to admin.php this file will contains all admin routes move this admin route group to our admin.php don't forget to import this root facade to this file and also import admin controller to this file now we finish our custom root file for admins create another file and rename to doctor.php this file will contains all doctor roots move this doctor root group to custom doctor roots file don't forget to add this root facade on top of this file also you have to import doctor controller to this file friends we have finished creating our custom root files now it's time to register our custom root files just go to app providers folder and open rootserviceprovider.php file custom root files must be registered inside this boot method let's start register user admin and doctor root files don't change this middleware just change this to user.php this name must be equal to this file name don't change this middleware just name this to admin.php this name must be equal to this file name also don't change this middleware just name this to doctor.php friends our custom root files have been successfully registered it's time to test our routes let's test as you can see we have this normal users table let's use this user email address for login now if i try to access user home page this will redirect me to the user login page because i didn't logged in if i use wrong password this will show me that i entered incorrect credentials but if i entered correct credentials this will redirect me to the user home page now if i try to access login page when i already logged in this redirects me to the home page because i already logged in also if i try to access user register page this also redirects me to the home page so our custom root file for normal users is working fine let's test admin routes if i try to access admin home page this will redirect me to the admin login page because i didn't logged in if i try to use wrong password this will shows me that i entered incorrect credentials but if i entered correct credentials this will redirects me to the admin home page friends our custom root file for admin is working fine let's test dr roots if i try to access doctor home page this will redirect me to the doctor login page because i didn't logged in but if i entered correct credentials this will redirects me to the doctor home page if i try to access doctor register page this will redirect me to dr home page because i already logged in friends this is how you can create your custom root file in laravel 8 thanks for watching this video
Info
Channel: Irebe Library
Views: 542
Rating: undefined out of 5
Keywords: irebe library, how to, add custom route files, laravel 8 tutorial, route, routes
Id: J8vj32Byf0Q
Channel Id: undefined
Length: 8min 4sec (484 seconds)
Published: Sun Aug 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.