在routes目录下新建后台路由routes/api/backend.php和前台路由routes/api/frontend.php
修改app/Providers/RouteServiceProvider.php代码,目的将欢迎首页访问地址由http://your_host变成http://your_host/web。将api访问地址由http://your_host/api修改为http://your_host
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::prefix('web')
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
routes/api.php 代码修改为:
<?php
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::prefix('frontend')->group(function () {
require_once __DIR__."/api/frontend.php";
});
Route::prefix('backend')->group(function () {
require_once __DIR__."/api/backend.php";
});
routes/api/backend.php 代码修改为:
<?php
Route::get('donkey', function(){
return "hello donkey".PHP_EOL;;
});
routes/api/frontend.php 代码修改为:
<?php
Route::get('lion', function(){
return "hello lion".PHP_EOL;;
});
演示效果如下:
源代码地址:https://github.com/windawake/laravel-repository-pratice/tree/master