【问题标题】:Why does findmany() not work here - Lumen/Laravel?为什么 findmany() 在这里不起作用 - Lumen/Laravel?
【发布时间】:2020-05-20 07:41:54
【问题描述】:

我正在尝试在一个集合上使用 findmany(),我用这个检查了它是否是一个集合:

if ($join instanceof Collection) {
  log::info("deemed collection");
}else{
  log::info("not deemed collection");
}

虽然它似乎是一个集合,但我仍然收到错误:

BadMethodCallException

Method Illuminate\Database\Eloquent\Collection::findmany does not exist.

当我尝试对其使用 findmany() 时,如下所示:

$join = $join->findmany(1);

$join 是这样创建的:

$join = coretable::with($permittedTables)->get();

其中$permittedTables 是一个表名数组,因此该集合可以包含任意数量的表和表的组合。

为什么我不能使用这个集合中的 findmany() 方法?它应该可以从集合中访问,不是吗?

【问题讨论】:

    标签: php laravel eloquent lumen


    【解决方案1】:

    $join = $join->findMany([1,2,3]);

    findMany 适用于 Id 数组。

    findMany 应该是驼峰式的。

    【讨论】:

      【解决方案2】:

      集合上没有findMany方法,只有find

      在从数据库中检索记录之前,您可以在查询构建器上调用 findMany,例如:

      $join = coretable::with($permittedTables)->findMany([1]);
      

      【讨论】:

        猜你喜欢
        • 2013-05-16
        • 2019-02-10
        • 2017-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多