Warm tip: This article is reproduced from stackoverflow.com, please click
eloquent laravel lumen php

Why is lumen/laravel throwing error "Too few arguments passed" when using find/findmany?

发布于 2020-03-31 22:57:55

I have an array of ids I want to use to get matching records from a table. Code looks like this:

$res = Extensiontables_Registry::findmany($ids[0])->get();

The full context looks like this:

  public function getData(Request $request){
    $ad_groupsOfUser = $this->getRoles($request);
    $ids = $ad_groupsOfUser->pluck('id');

    $res = Extensiontables_Registry::findmany($ids[0])->get();

    return response()->json($res, 200);
  }

  public function getRoles(Request $request)
  {
    $ad_groups = Ad_user::find($request->decodedToken->user_id)->ad_groups()->get();

    //return response()->json($roles, 200);
    return $ad_groups;
  }

$ids definitely is an array and contains values, I've debugged it. But why isn't it working with find/findmany? This is the full error I get:

 (1/1) ArgumentCountError

Too few arguments to function Illuminate\Support\Collection::get(), 0 passed in E:\aether-backend\app\Http\Controllers\UserController.php on line 49 and at least 1 expected
Questioner
Narktor
Viewed
292
Syed Abdur Rehman Kazmi 2020-01-31 19:40

Once you use find it fetches the data for you. get() is used after a where clause

Model::find();

Model::where(['key' , 1])->get();