How to add a conversion using laravel media library from only one of the multiple uploaded images

115 Views Asked by At

I'm uploading multiple images for a property and everything works well. The images and their conversions are uploaded successfully. However, a conversion is created for every image of a given property but I'd like to create a conversion only for the first image of the multiple uploads. How can I achieve that?

My controller logic

 foreach ($request->file('images') as $image) {
      $property->addMedia($image)->withResponsiveImages()->toMediaCollection();
    }

My model conversion logic

  public function registerMediaConversions(Media $media = null): void
  {
    $this->addMediaConversion('small_thumb')
      ->width(300)
      ->height(200);
  }
0

There are 0 best solutions below