PHP:Laravel-admin api-tester 安装配置及问题

一:安装

参考链接:https://packagist.org/packages/laravel-admin-ext/api-tester

composer require laravel-admin-ext/api-tester -vvv
php artisan vendor:publish --tag=api-tester

二:配置

打开config/admin.php ,修改extensions

'extensions' => [
        'api-tester' => [
            // route prefix for APIs
            'prefix' => 'api',
            // auth guard for api
            'guard'  => 'api',
            // If you are not using the default user model as the authentication model, set it up
            'user_retriever' => function ($id) {
                return \App\Models\User::find($id);
            },
        ]
    ]

三:测试

在route/api.php 路由里添加一个测试路由

Route::get('test', function () {
    return 'hello world';
});


1,点击请求测试,这里会报一个Call to undefined function array_get()错误。原因是 laravel5.7 以上弃用array_get()帮助函数
解决办法:

use Illuminate\Support\Arr;
array_get改成Arr::get

2,测试test,这里会报Symfony\Component\HttpKernel\Exception\NotFoundHttpException">NotFoundHttpException。测试下来\vendor\laravel-admin-ext\api-tester\src\ApiTesterController.php 的handle方法请求的route地址问题。
解决办法:

      //在.env里添加
      API_DOMAIN=http://localhost/
      // \vendor\laravel-admin-ext\api-tester\src\ApiTesterController.php 的handle方法里$tester->call($method, $uri, $parameters, $user);之前添加上
      $uri = env('API_DOMAIN').$uri;
posted @ 2021-01-19 16:32  wish_yang  阅读(457)  评论(0编辑  收藏  举报