繁体   English   中英

API资源-调用未定义的方法:: toArray()

[英]API Resources - Call to undefined method ::toArray()

我正在尝试更改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);

});

我的收件箱类型

 public function toArray($request)
   {
       return parent::toArray($request);
   }

错误

调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Builder :: toArray()

给出错误的行是

return parent::toArray($request);

在$ inboxtype = ....中,它缺少-> get()。 所以应该是这样的:

$inboxtype =   Messages::where('receiver_id', $user_id)
               ->with('sender')
               ->with(['bookings' => function($query) {
                            $query->with('currency');
                        }])
               ->with('item_address')
               ->orderBy('id','desc')
               ->get();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM