I have a table in a BD and I want to extract from it 10-in-10 records to store an image and have no memory problems. I'm working with laravel
The code I use is:
$imagenes = new Collection();
DB::table('inscripciones')->orderBy('id')->chunk(10, function ($inscripciones)
{
foreach ($inscripciones as $inscripcion)
{
$imagenes->push($inscripcion->foto);
$imagenes->push($inscripcion->scan_pasaporte);
};
});
But it gives an error: It tells me that $imagenes
is not defined.
It can be solved by entering the definition ($imagenes = new Collection();)
within the foreach, but of course, the result is not what you want.
Any way that $imagenes
is valid within the function?
I feel if I do not explain it very well. Thanks