Reputation: 39
In a custom artisan command, I'm trying to access all of the members of a model (e.g. User) with User::all()
.
Records exist in the database for this model but User::all() in the command just returns "Illuminate\Database\Eloquent\Collection {#3308}"
instead of the actual results. Dumper does not show any item inside of the collection, just show how many items collection have
This seems to only happen within the command as I am able to pull the results using Tinker.
Does anyone know why this would be happening?
Upvotes: 2
Views: 440
Reputation: 2866
Laravel uses Symfony's VarCloner class and in this class has $maxItems
attribute which is defined 2500 as default. ($maxItems
coming from parent class)
If you want to get more items you may override or extend Illuminate/Support/Debug/Dumper.php
class
this is default
public function dump($value)
{
if (class_exists(CliDumper::class)) {
$dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper;
$dumper->dump((new VarCloner)->cloneVar($value));
} else {
var_dump($value);
}
}
But you can say that you want to dump more items;
public function dump($value)
{
if (class_exists(CliDumper::class)) {
$dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper;
$cloner = new VarCloner;
$cloner->setMaxItems(4000);
$dumper->dump($cloner->cloneVar($value));
} else {
var_dump($value);
}
}
Upvotes: 1