I try to load multiple images through the laravel queue as follows:
Controller:
foreach ($this->imagenes as $pathGaleria) {
$imagenes = $pathGaleria;
$nombre = Str::random(10) . $imagenes->getClientOriginalName();
$ruta = public_path() . '\imagenesPropiedades/' . $nombre;
dispatch(new ProcesarImagenes($pathGaleria, $ruta));
$img = imgPropiedades::create([
'url' => '/imagenesPropiedades/' . $nombre,
'property_id' => $this->propiedadId
]);
}
Job:
public $pathGaleria;
public $ruta;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($pathGaleria, $ruta)
{
$this->pathGaleria = $pathGaleria;
$this->ruta = $ruta;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$img = $this->pathGaleria;
$rut = $this->ruta;
//make recibe la imagen
Image::make($img)
->resize(800, null, function ($constraint) {
$constraint->aspectRatio();
})
->save($rut);
}
I get the following error: Serialization of 'Livewire\TemporaryUploadedFile' is not allowed.
Any suggestion will be of great value to me.
I would suggest to pass the getRealPath()
of the temporary file and later use file_get_contents()
and continue from there onward.
e.g.
dispatch(new ProcesarImagenes($pathGaleria->getRealPath(), $ruta));
under your job handle()
$img = file_get_contents($this->pathGaleria);
Also, make sure to use queue:listen
on your local environment, that way you don't have to restart queue after making changes to the Job file.