I found a laravel project that place routes not only in web.php also in another folders and include this files from other What kind of logic is that I never see and I never can access their routes here are folder struture
can accest routes by this way in laravel?
CodePudding user response:
Create files as group/admin.php
per needed modules in the /routes
folder.
Open /routes/group/admin.php
. Inside this file we will place all admin related routes.
<?php
use Illuminate\Support\Facades\Route;
Route::prefix("admin")->group(function(){
Route::get("/", [AdminController::class, "index"]);
});
We have separated each module's routes into different route files. More importantly, the application routes are now more readable.
Next, open RouteServiceProvider.php
inside the /app/Providers
folder.
Inside this class, search for boot()
method.
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
// Admin Route file
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/group/admin.php'));
});
}
All done!
Test it out by opening the project in the terminal and typing the command to start development server:
$ php artisan serve
Then view in the browser at:
http://127.0.0.1:8000/admin