如下是我写的API接口的controller:
<?phpnamespace 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的技术栈中,怎么去为每个接口的返回体配置code
和message
字段?及其相应的内容?