Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Telexx's avatar
Level 5

Laravel media-library responsive images

I'm attempting to implement the responsive images feature of Laravel Spatie Media Library, but for some reason, it's not generating the images. I've tried registering a media conversion and applying withResponsiveImages there, as well as directly after $model->addMedia(), and even downgrading to different versions of media-library, but none of these solutions have resolved my issue.

How I upload the image

  $request->validate([
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);

    $image = Image::create([
       'name' => $request->image->getClientOriginalName()
    ])
    ->addMedia($request->image)
    ->withResponsiveImages()
    ->toMediaCollection();

How I retrive the model to display the responsive images

    $image = Image::first();
    return view('welcome', compact('productsForMenu', 'productsForSlider','image'));

And how I display the image

    {{$image->getFirstMedia()}}

The image is uploaded under /public/media/id/image.jpg, but no responsive images are generated. When I display it, the srcset attribute isn't applied. What could I be doing wrong? Is it a media-library-pro feature?

If this don't work, what alternatives do I have to create responsive images?

0 likes
1 reply

Please or to participate in this conversation.