在lavravel的model中,因为用了first,如下:

  1. public function detail($uuid)
  2. {
  3. $detail = Task::where('uuid', $uuid)
  4. ->with('userDetailLog')
  5. ->first(['title', 'uuid', 'admin_name', 'id']);
  6. return $detail;
  7. }

因为firsrt返回的不是一集合了,在resource中不能再用

  1. Route::get('/resource/posts', function () {
  2. return PostResource::collection(Post::all());
  3. });

这个应该改为:

  1. Route::get('/resource/posts', function () {
  2. return PostResource::make(Post::all());
  3. });

或者用new

  1. Route::get('/resource/posts', function () {
  2. return new PostResource(Post::all());
  3. });

Resource中的make方法返掉用callStatic方法,生成一个新的集合.问题解决了.

参考:https://laracasts.com/discuss/channels/laravel/laravel-55-api-resource-call-to-undefined-method-illuminatedatabasequerybuildermapinto?page=1

分类: web

标签:   laravel