controller grouping

If a group of routes all utilize the same controller, you may use the controller method to define the common controller for all of the routes within the group. Then, when defining the routes, you only need to provide the controller method that they invoke.

Route::controller($param, $action);

// grouping the common controller
// dont write same controller repeatedly
Route::controller(['WelcomeController'], function () {
		
    // you can set the controller method as string
    Route::get('/settings', 'settings');
	
    // you can also set the controller method as array
    Route::get('/settings/add', ['create']);
    
    // you can also add middleware auth to a grouped controller
    // if there's no global middleware set in the parent
    Route::get('/settings/add', ['create', ['auth']]);

});

Last updated