I have a problem with Laravel\'s ORM Eloquent chunk() method. It misses some results. Here is a test query :
$destinataires = Destinataire::where(\'statut\', \'&
For anyone looking for a bit of code that solves this, here you go:
while (Model::where('x', '>', 'y')->count() > 0)
{
Model::where('x', '>', 'y')->chunk(10, function ($models)
{
foreach ($models as $model)
{
$model->delete();
}
});
}
The problem is in the deletion / removal of the model while chunking away at the total. Including it in a while loop makes sure you get them all! This example works when deleting Models, change the while
condition to suit your needs!