How to change the default route Laravel?

Basic routes in Laravel take in a URI and closure. Laravel routes are defined in various files of the routes directory. From these, the web.php file defines the main routes required for your web interface. They are assigned to the web middleware group and provide session state and CSRF protection. All routes are then auto-loaded from the RouteServiceProvider of an application. The routes inside api.php are stateless and assigned to the api middleware group. These routes can be accessed by our browser and have the default syntax as shown below.

Route::get('/route_1', 'HomeController@getScratchData')->name('route_name');
Route::get('/route_2', ['as' => 'route_name', 'uses' => 'HomeController@getDevData']);

Change default route Laravel

We can simply edit the route definition in web.php or api.php to alter the default routes. You can modify the route definition and use the specific route and associated controller function. The code snippet below shows how you can call the index method from the HomeController in the /home route in a. different way than the default configuration.

Route::get('/home', 'HomeController@index');

After altering, save the changes in the web.php file and access your application by adding the route name. For example, https://scratchcoding.dev/home.