最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Failed Image Conversion on Laravel Queue from Spatie Media Library - Stack Overflow

programmeradmin0浏览0评论

I am currently using Spatie media library for my personal project using Laravel 11.41.3 with Filament 3.2.137 and Filament's Spatie Media library 3.2.137. I have followed the installation from Filament's Spatie Media library and successfully migrated the related media tables. Afterwards, I went over to Spatie media library documentation to setup the Laravel model for using the media library as follows:

use Spatie\MediaLibrary\HasMedia;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\InteractsWithMedia;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
    
class Product extends Model implements HasMedia

{

use InteractsWithMedia;

    public function registerMediaConversions(?Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->width(100);

        $this->addMediaConversion('small')
            ->width(480);

        $this->addMediaConversion('large')
            ->width(1200);
    }

Note that I also setup the media conversion here as well. Then, I setup the form for uploading the images with Filament resource page as follows:

<?php

namespace App\Filament\Resources\ProductResource\Pages;

use Filament\Actions;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Resources\ProductResource;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

class ProductImages extends EditRecord
{
    protected static string $resource = ProductResource::class;

    public function form(Form $form): Form {

        return $form->schema([
            SpatieMediaLibraryFileUpload::make('images')
            ->image()
            ->multiple()
            ->openable()
            ->panelLayout('grid')
            ->collection('images')
            ->reorderable()
            ->appendFiles()
            ->preserveFilenames()
            ->columnSpan(2)
        ]);
    }

    protected function getHeaderActions(): array
    {
        return [
            Actions\DeleteAction::make(),
        ];
    }
}

And in Filament resource file, I added additional configuration for accessing the image upload page.

public static function getPages(): array
{
    return [
        'index' => Pages\ListProducts::route('/'),
        'create' => Pages\CreateProduct::route('/create'),
        'edit' => Pages\EditProduct::route('/{record}/edit'),
        'images' => Pages\ProductImages::route('/{record}/images'), <--- Added this line
    ];
}

public static function getRecordSubNavigation(Page $page): array {

    return $page->generateNavigationItems([
        EditProduct::class,
        ProductImages::class, <--- Added this sub-navigation
    ]);
}

The original images were uploaded to the disk storage as well as store to the database successfully. However, the image conversion fails during the Laravel queue whether on listen or work. The following image shows the terminal output of the error:

I have searched through forums related to this issue but none exist. I would appreciate any guidance on why this issue occurs. Thank you!

发布评论

评论列表(0)

  1. 暂无评论