将 "dingo/api": "2.1" 改为最新版本呢后执行 composer uodate安装Lumen:
lumencomposer create-project --prefer-dist laravel/lumen web
在composer.json 中的
"require": {
"php": ">=7.1.3",
"dingo/api": "2.1", // 添加在一句 整理要用最新版本的、不然会报错
"laravel/lumen-framework": "5.7.*",
"vlucas/phpdotenv": "~2.2",
"webpatser/laravel-uuid": "^3.0"
},
composer update
如果报上图错误:将 "dingo/api": "2.1" 改为最新版本呢后执行 composer uodate
配置:
bootsstrap/app.php
$app->withFacades();
$app->withEloquent();
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
// 登陆中间键
$app->routeMiddleware([
'auth_token' => App\Http\Middleware\MemberTokenMiddleware::class,
]);
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
$app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
.env
###################################################################
# dingo api config head ===> Accept: application/vnd.hh.v1+json #
API_STANDARDS_TREE=vnd # 分支树 #
API_SUBTYPE=hh # 应用的简称 #
API_DOMAIN=URL # API 域名 #
API_VERSION=v1 # 版本号-默认:v1 #
API_DEFAULT_FORMAT=json # 交互数据类型JSON #
API_DEBUG=false # debug #
####################################################################
路由:
// 加载 dingo api
$api = app('Dingo\Api\Routing\Router');
// 第一个版本的路由群组
$api->version('v1', ['namespace' => 'App\Http\Controllers\V1',], function ($api) {
});
// 第二个版本的路由群组
$api->version('v2', ['namespace' => 'App\Http\Controllers\V2',], function ($api) {
});
控制器:
访问地址:
URL/member/register
Header 传参数
Accept: application/vnd.hh.v1+json
网友评论