传递给App \\ Http \\ Controllers \\ ApiController :: showall()的参数1必须是Illuminate \\ Support \\ Collection的实例,App \\ User的实例

时间:2019-04-18 21:17:39

标签: laravel-5.7

我正在使用关系显示具有模型的数据集合。...

  public function index($id){
              $user = User::with('files.comment',
            'files.likes','files.dislike')->get()->find($id);
              // return response()->json(['data' => $user], 200,[],JSON_NUMERIC_CHECK);

      //while using return response i am getting all my data bt using whrn trait showall method it gives arguments pass error

         return $this->showall($user);
    }

我的性状特征响应

protected function showall(Collection $collection, $code =  200){
    if ($collection ->isEmpty()) {
      return $this->successResponse(['data'->$collection],$code);
    }

    $transformer = $collection->first()->transformer;
    $collection = $this->sortData($collection, $transformer);

    $collection = $this->transformData($collection, $transformer);
    return $this->successResponse( $collection,$code);
   }

如何解决此问题,请告诉我...

0 个答案:

没有答案