How to Create Custom Route File in Laravel 8

Routes are entry points to a Laravel application. There are two route files available in Laravel 8 by default. These are called web.php and api.php.

If required one can create custom route file in Laravel easily.

In this article I am going to show you how to create Custom Route File in Laravel 8.

Perquisite: An installed and working Laravel Application

Essentially there are two methods to create a custom Laravel route file. I will show the first one in this post and second one later sometime. For ones with older version of Laravel, can try this link.

In this post I will demonstrate creating /admin routes here, for example calling http://127.0.0.1:8000/admin

Let’s start doing it now.

Create a file routes/admin.php with the following code:

Next, open the app/Providers/RouteServiceProvider.php and find public function boot() in it. Add the following code to it, just above or below the existing lines of code for web and api routing.


So it becomes:

You should see I am an admin message on your browser window at http://127.0.0.1:8000/admin.

Note: Clear cache and test the url if it does not update. You can create a simple create cache route in your web.php routes file as shown below:

You can follow this article about clearing cache in Laravel application.

In next articles I will show you how to create a set of an Admin routes so you can login via web routes but still protect your admin area via custom user login access check. (Edit: It is already there, check it now!)

I hope you liked this article about Create Custom Route File!

Leave a Reply