fanisa's avatar

Save file on upload (array of images, one file model)

Hello! I have some images

@foreach($images as $image)
		...
        <input type="file" wire:model="newImage" />
		...
		<button wire:click="save({{ $loop->index }})">Save</button>
@endforeach

I don't want to use any submit button to save the image, just save it on uploading

For example,

public function updatedNewImage()
    {
        // here I need to retrieve $index
    }

How to do this?

0 likes
2 replies
CorvS's avatar

@fanisa You could use wire:change instead and pass the index

@foreach($images as $image)
    ...
    <input type="file" wire:change="save({{ $loop->index }})" />
    ...
@endforeach

and then work from there

public function save($index)
{
    $this->images[$index] ...
}
fanisa's avatar

ok, in this case how can I retrieve the file instance, than was returned by wire:model?

Please or to participate in this conversation.