gpt4 book ai didi

php - "message": "Undefined property: $response", 带有 laravel 5.2 的 dingo api

转载 作者:行者123 更新时间:2023-12-02 06:31:08 24 4
gpt4 key购买 nike

我正在尝试使用 laravel 5.2 实现 dingo API

下面是我写的测试dingo的函数

public function profile()
{
try {
$user = JWTAuth::parseToken()->toUser();
if (!$user) {
return response()->json(['error' => 'User Not Found'], 500);
}
} catch (\Tymon\JWTAuth\Exceptions\JWTException $ex) {
return response()->json(['error' => 'Something went wrong'], 500);
}
//return response()->json(['user' => $user->with('profile')->where('id', $user->id)->first()], 200);
return $this->response->array($user->toArray());

}

我用的时候很好用

    return response()->json(['user' => $user], 200);

但是当我按照 dingo 语法使用下面的代码行时。显示错误

    return $this->response->array($user->toArray());

基本上,dingo 定义的函数都不起作用。如何解决?

最佳答案

你在使用野狗 helper 吗?来自documentation

The response builder provides a fluent interface to easily build a more customizable response. The response builder is generally used in conjunction with transformers.

To utilize the response builder your controllers should use the Dingo\Api\Routing\Helpers trait. To save importing and using the trait on all your controllers you can simply create a base controller that all your API controllers will extend.

use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;

class BaseController extends Controller
{
use Helpers;
}

关于php - "message": "Undefined property: $response", 带有 laravel 5.2 的 dingo api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36858575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com