Multiple photo Hello, Can i know what the wrong with that code ?
foreach ($this->images as $image) {
$extension = $image->getClientOriginalExtension();
$filename = time() . '.' . $extension;
$image->storeAs('product_multiple_image', $filename, 'real_public');
$this->images = $filename;
ProductImage::create([ 'product_id' => $this->product->id, 'image' => $filename ]);
}
It's take the multiple image in database but all photos as 1 , That mean if i uploaded 3 photos in database they are 3 but in images folder only 1 photo
My blade
<input type="file" id="image" wire:model="images" name="image[]"
class="form-control" multiple />
It could be because you're overwriting $this->images with the $filename during the first run of the loop before you store it in the database.
$this->images = $filename;
ProductImage::create([ 'product_id' => $this->product->id, 'image' => $filename ]);
@thinkverse I tried it like that and it stored in database
foreach ($this->images as $image) {
$extension = $image->getClientOriginalExtension();
$filename = time() . '.' . $extension;
$filename = $image->storeAs('product_multiple_image', $filename, 'real_public');
ProductImage::create([ 'product_id' => $this->product->id, 'image' => $filename ]);
}
But didn't store in the 'product_multiple_image' folder
Use Str::random instead of time() for naming images.
@MichalOravec Sorry, In the folder it's done the photos in uploaded , But not showed for user, That's my blade
@foreach ($productimage as $images)
<div class="col-4">
<img src="{{ asset('/product_multiple_image') . '/' . $images->image }}" />
</div>
@endforeach
@kazzuya Think about what you store in the database...
Here's how I do it.
foreach ($this->images as $image) {
$filePath = $image->store('product_multiple_image', 'public'); // Store the file with a unique name in the "public" driver
ProductImage::create([ 'product_id' => $this->product->id, 'image' => $filePath ]);
}
@foreach ($productimage as $images)
<div class="col-4">
<img src="{{ Storage::url($images->image) }}" />
</div>
@endforeach
Please sign in or create an account to participate in this conversation.