Reputation: 185
Making routes of various pages of a website in web.php makes it bulky and unstructured. So my question is is there any way to save it in separate files?
// Calling Registration function
Route::any('/admin-store','AdminUserController@store')->name('admin-reg');
// Redirecting to Registration page
Route::get('/admin-registration','AdminUserController@index')->name('admin-registration');
// Redirecting to login page
Route::get('/admin-login','AdminLoginController@index')->name('admin-login');
// Redirecting to Admin Profile Page
Route::get('/admin-profile','AdminProfileController@index')->name('admin-profile');
// Calling Login function
Route::post('admin-login-result','AdminLoginController@login')->name('admin-log');
// Calling Function to Update Profile
Route::post('admin-edit-profile','AdminEditController@updateProfile')
->name('admin-edit-profile');
// Redirecting to Profile Edit page
Route::get('/admin-edit-profile','AdminEditController@index')->name('admin-edit');
Upvotes: 4
Views: 4977
Reputation: 14241
Yes, you can store routes in different files.
Create your new route file, for this example I'll name it users.php
and store there the related routes:
Route::get('/my-fancy-route', 'MyCoolController@anAwesomeFunction');
// and the rest of your code.
Add here a new method, i'll call it mapUserRoutes
:
/**
* Define the User routes of the application.
*
*
* @return void
*/
protected function mapUserRoutes()
{
Route::prefix('v1') // if you need to specify a route prefix
->middleware('auth:api') // specify here your middlewares
->namespace($this->namespace) // leave it as is
/** the name of your route goes here: */
->group(base_path('routes/users.php'));
}
map()
methodIn the same file(RouteServiceProvider.php
), go to the top and add your new method inside the map()
function:
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
// some other mapping actions
$this->mapUserRoutes();
}
I'm not fully sure if this is neccesary but never hurts to do:
Stop your server (if runing)
do php artisan config:clear
Start your server.
Upvotes: 6