简要描述:
- 在laravel根目录下面的routes目录下,有几个文件。其中web.php为网页的路由配置文件,而api.php就是api的路由配置文件。
举例:
<?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!
|
*/
// api
Route::group(array('domain' => 'abc.com'), function()
{
Route::any('/', function() {
$ctrl = \App::make("\\App\\Http\\Controllers\\" . ucfirst('api') . "\\" . ucfirst('index') . "Controller");
return \App::call([$ctrl, ucfirst('index')]);
});
});
注意:
- 与web路由不同,访问API路由,是需要在域名后面加上api的。比如:访问api模块下,index控制器中的index方法,地址如下:
https://abc.com/api/
网友评论