我正在尝试更改json返回值,因此我正在使用API资源 我的路线:
Route::get('inbox/all', function(){
$user_id = Auth::user()->id;
$inboxtype = Messages::where('receiver_id', $user_id)->with('sender')->with(['bookings' => function($query) {
$query->with('currency');
}])->with('item_address')->orderBy('id','desc');
return new InboxType($inboxtype);
});
我的InboxType
public function toArray($request)
{
return parent::toArray($request);
}
错误
调用未定义的方法Illuminate \ Database \ Eloquent \ Builder :: toArray()
给出错误的行是
return parent::toArray($request);
答案 0 :(得分:4)
在您的$ inboxtype = ....中,缺少-> get()。所以应该像这样:
INSERT INTO DRAW (idcliente, date draw, stage)
SELECT id client, now () AS date_sorteo, 'S1' AS stage FROM client ORDER BY rand () LIMIT 4