【问题标题】:Laravel Livewire queues Serialization is not allowedLaravel Livewire 队列不允许序列化
【发布时间】:2020-12-06 01:32:29
【问题描述】:

我尝试通过 laravel 队列加载多张图片如下:

控制器:

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
        ]);
    }

工作:

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);
}

我收到以下错误:不允许序列化“Livewire\TemporaryUploadedFile”。

任何建议都会对我很有价值。

【问题讨论】:

    标签: laravel queue laravel-livewire


    【解决方案1】:

    我建议传递临时文件的getRealPath(),然后使用file_get_contents() 并从那里继续。

    例如

    dispatch(new ProcesarImagenes($pathGaleria->getRealPath(), $ruta));

    在你的工作下handle()

    $img = file_get_contents($this->pathGaleria);

    另外,请确保在您的本地环境中使用queue:listen,这样您就不必在更改作业文件后重新启动队列。

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 2019-01-30
      • 2018-02-25
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多