Hello developers in this tutorial we will discuss about how to create custom routes in Laravel 10.
|1||What are routes|
|2||Register new route|
|3||Register route in RouteServiceProvider|
|4||Register route in Kernel|
Routes are define as where we register our application urls or we also define it as it is a path or bridge that connects our frontend with backend like whenever we sends data from frontend it goes to backend with the help of route as in route file we mention our all url's along with backend functions .
Also read:HOW TO MAKE TRAITS IN LARAVEL 9
For registering new route we simply create a file routes/admin.php , here for example we are using admin.php as our new route file you can use any appropriate route according to your requirment, as in our new route file we want all the same properties as in web.php file.
code for admin.php Copy
As we create our new route routes/admin.php and now we register our route in app/Providers/RouteServiceProvider.php to register our new route so that our laravel application give access to our new route.
code for RouteServiceProvider : Copy
As shown we register our admin.php file with the prefix of admin that means our our url inside admin.php will be call by prefix admin/ like we have to call home url then we will call with admin/home Now after register our route in RouteServcieProvider as to provide similar properties with the web.php we will also register in app/Http/Kernel.php.
Main reason for register route in app/Http/Kernel.php to provide the same middleware properties as of web.php as in kernel you can also provide the custom middleware as it will apply on all the routes in admin.php .
code for kernel.php :Copy
Also read: ACCESSOR AND MUTATOR IN LARAVEL 9
video:: How to Create Custom Route File in Laravel 10 | Learn Laravel 10 | Laravel 10 basics to advance