0

如下是我写的API接口的controller:

<?php

namespace App\Http\Controllers\Lucky;

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController as BaseController;
use App\Models\Card;
use App\Http\Transformers\CardsTransformer;

class CardsController extends BaseController
{
    public function test(Request $request) {
        $unionId = $request->input('unionId');
        $card = new Card;
        $card->union_id = $unionId;
        $card->fi_card = 1;
        $card->s_card = 2;
        $card->t_card = 3;
        $card->fo_card = 4;
        $card->save();
        return $this->response->item($card, new CardsTransformer());
    }
}

这样写,调用该接口得到的返回体如下:

{
    "data": {
        "unionId": "test",
        "fiCard": 1,
        "sCard": 2,
        "tCard": 3,
        "foCard": 4
    }
}

可是我认为正确的API接口的返回体应该如下:

{
    code:0,
    message:"ok",
    data:{},
    useTime:0.017374038696289062
}

请问在laravel和dingo/api的技术栈中,怎么去为每个接口的返回体配置codemessage字段?及其相应的内容?

2月13日提问
1 个回答
0

已采纳

大家可以参考 https://learnku.com/laravel/t...
欢迎指正

撰写答案

推广链接