Call to undefined method Illuminate\Database\Query\Builder::make()

845 views Asked by At

Simply trying to use the example straight from the docs throws this error. I'm banging my head against the wall, I tried everything.

$collection = Collection::make([1, 2, 3]);

Despite the above being pulled right from the docs I get this:

BadMethodCallException in Builder.php line 1992:
Call to undefined method Illuminate\Database\Query\Builder::make()

Need to know how to make a custom collection from an array. I do not understand why this is difficult.

2

There are 2 answers

0
Marcin Nabiałek On

To create collection you can simply use collect helper method this way:

$collection = collect([1, 2, 3]);

which is equivalent to:

$collection = new Collection([1,2,3]);
0
The Alpha On

You may try this:

// Notice the namespace here, probably you've used wrong namespace
$collection = \Illuminate\Support\Collection::make([1, 2, 3]);

Or using this helper function:

$collection = collect([1, 2, 3]);