Php 为什么在使用find/findmany时lumen/laravel抛出错误“传递的参数太少”?

Php 为什么在使用find/findmany时lumen/laravel抛出错误“传递的参数太少”?,php,laravel,eloquent,lumen,Php,Laravel,Eloquent,Lumen,我有一个ID数组,用于从表中获取匹配的记录。 代码如下所示: $res = Extensiontables_Registry::findmany($ids[0])->get(); public function getData(Request $request){ $ad_groupsOfUser = $this->getRoles($request); $ids = $ad_groupsOfUser->pluck('id'); $res = E

我有一个ID数组,用于从表中获取匹配的记录。 代码如下所示:

$res = Extensiontables_Registry::findmany($ids[0])->get();
  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;
  }
整个上下文如下所示:

$res = Extensiontables_Registry::findmany($ids[0])->get();
  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绝对是一个数组,包含值,我已经调试过了。 但是为什么它不能与find/findmany一起工作呢? 这是我得到的全部错误:

 (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

一旦您使用find,它就会为您获取数据。get在where子句之后使用

Model::find();

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

一旦您使用find,它就会为您获取数据。get在where子句之后使用

Model::find();

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

您可以使用find代替findMany

因为您试图获取一个数据。好的方法是使用这种方法

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

    $response = Extensiontables_Registry::whereIn($ids->toArray())->get();

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

您可以使用find代替findMany

因为您试图获取一个数据。好的方法是使用这种方法

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

    $response = Extensiontables_Registry::whereIn($ids->toArray())->get();

    return response()->json($response, 200);
  }
使用方法:检查

使用方法:检查

您不需要使用get after find。“查找”已从数据库中获取1个结果,“获取”将获取一组结果。不需要在“查找”之后使用“获取”。Find已从数据库中获取1个结果,get获取一组结果。