安装Dingo需要下面的环境:
- Laravel 5.1 或 lumen 5.1 +
- php 5.59+
1. 修改composer.json
文件,添加下面的代码:
"require": { "dingo/api": "1.0.*@dev" }
2 .然后根目录下执行composer update
3. Laravel的配置
在config/app.php
中的providers
数组中添加
'providers' => [ DingoApiProviderLaravelServiceProvider::class ]
通常情况下,我们都会配置Dingo,我们可以生成自己我们可以修改的dingo配置文件,终端里执行下面的代码
php artisan vendor:publish --provider="DingoApiProviderLaravelServiceProvider"
4. 门面
Dingo 中自带了两个门面,你可以根据自己的需要添加
//This is a facade for the dispatcher, however, it also provides helper methods for other methods throughout the package. DingoApiFacadeAPI //This is a facade for the API router and can be used to fetch the current route, request, check the current route name, etc. DingoApiFacadeRoute
为了方便,可以为上面的门面设置别名
'aliases' => [ 'APIRoute' => DingoApiFacadeRoute::class, 'API' => DingoApiFacadeAPI::class, ]