Skip to content

addMediaFromDisk Method not defined when used in Queue Job #3555

@gepopp

Description

@gepopp

Hi there,
im using the latest versions of laravel and livewire.

I have an existing Image model and i want to move the images to the media library, so i wanted to dispatch a job foreach existing image like so:

class MoveReleaseImage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct( public Image $image )
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        if(Storage::disk('s3')->exists($this->image->path) && Storage::disk('s3')->size($this->image->path) < 1024 * 1024 * 30){
            $this->image->addMediaFromDisk( $this->image->path, 's3' )
                    ->withResponsiveImages()
                    ->withCustomProperties( [
                        'alt'     => $this->image->alt,
                        'caption' => $this->image->description,
                    ] )->toMediaCollection('images', 'ir');
        }
    }
}

If i dispatchSync that job everthing works as expected but if i dispatch it on the queue i get an Method addMediaNotFound err.
The image model implemnts the HasMedia and uses the InteractsWithMedia trait:

class Image extends Model implements HasMedia
{


    use HasFactory, InteractsWithMedia;




    protected $guarded = [];




    protected $appends = [ 'path' ];

...

Is there any restirction if the app runs from the console?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions