温馨提示:本文翻译自stackoverflow.com,查看原文请点击:php - Why is lumen/laravel throwing error "Too few arguments passed" when using find/findmany?
eloquent laravel lumen php

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

发布于 2020-03-31 23:29:28

我有一个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;
  }

$ 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

查看更多

提问者
Narktor
被浏览
26
Syed Abdur Rehman Kazmi 2020-01-31 19:40

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

Model::find();

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