If I do this:
$obj = factory(Object::class)->make();
collect($obj);
I am returned a collection of type:
Illuminate\Support\Collection
Laravel also lets you define your own collections with their specific methods. In the model, you do:
public function newCollection(array $models = [])
{
return new CustomCollection($models);
}
and you would make your CustomCollection
, starting like this, in the file CustomCollection.php:
class CustomCollection extends Collection
{
I'm wondering how I can return a collection of type:
Illuminate\Database\Eloquent\Collection
or, in the case of creating my own custom collection, how could I return a collection of type:
App\Models\CustomCollection
I'd like to do this with the collect()
helper or any other way where I don't access the database for purposes of writing PHPUnit tests.
==========
EDIT: I'm using factory(Object::class)->make()
to spoof Eloquent objects which I was trying to roll into collections.
If you just do factory(Object::class, 1)->make()
instead, the factory rolls the single instance of Object::class
into an Eloquent collection for you.