I\'m new to Laravel and I am handed an existing application that is composed of two parts:
1 - An admin backend built on Laravel and uses Vueify
2 - The fron
You need to define a new route file, firstly add a new entry $this->mapApi2Routes();
in the map()
function in app\Providers\RouteServiceProvider
.
Then add a new function in that file, basically copying the mapApiRoutes()
function, call it mapApi2Routes()
. You can use different middleware etc. for the new file.
The last step would be adding a new file api2.php
in the routes
folder.
You can decompose routes in as many files as you want, you can also give each file its own prefix (like how api.php
routes start with /api
)
The modification need to be done in App\Providers\RouteServiceProvider
//in map() add $this->mapApiTwoRoutes()
public function map()
{
$this->mapApiRoutes();
$this->mapApiTwoRoutes();//<---this one
$this->mapWebRoutes();
}
//now add the method mapApiTwoRoutes
protected function mapApiTwoRoutes()
{
Route::prefix('api2')//<-- prefix in the url
->middleware('api')//<-- api middleware (throttle and such check App\Http\Kernal.php)
->namespace('App\Http\Controllers') //<-- you can modify the namespace of the controllers
->group(base_path('routes/apiTwo.php'));//<-- file containing the routes
}
And that's it.