Search code examples
phplaraveleloquentlumen

Why does findmany() not work here - Lumen/Laravel?


I'm trying to use findmany() on a collection, I checked whether it is a collection or not with this:

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

While it seems to be a collection, I still get the error:

BadMethodCallException

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

When I try to use findmany() on it, like so:

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

The $join was created this way:

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

Where $permittedTables is an array of tablenames, so the collection can consist of any number and combination of tables.

Why can't I use the findmany() method from this collection? It should be accessible from collections, shouldnt it?


Solution

  • There is no findMany method on the collection, only find.

    You can call findMany on the querybuilder before retrieving the records from the database, something like:

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