🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

Working with multiple image select in Laravel Livewire

↗ Quelle (dev.to)
🗣️ Stimme:

In this article, I am going to show you a simple idea to fix the loss of previously selected image/images whenever you want to select more images using livewire with laravel.



I know there are several ways to achieve this but I find this method very easy with the help of some livewire lifecycle hooks which are the




Updating and the Updated hooks.




This screenshot shows the full code needed by your livewire component class



full code



Let's start by looking at what Updating and Updated hooks do. Then, I will explain the codes in the above screenshot step by step.






Updating:



This runs before any update to the Livewire component's data is completed.






Updated:



This runs after any update to the Livewire component's data is completed.



The code explanation goes thus:



First, add the WithFileUploads trait to your component. Then declare the following properties




CODE
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;

class Create extends Component {
use WithFileUploads;
public $images = [], $prevImages;
}






In your blade template, add an input tag with a type of file and set the model name as images like this:




CODE
<input type="file" wire:model="images" multiple accept="image/jpg,image/jpeg,image/png" />






So if you attempt to select multiple images, Livewire will handle it and render the image for you and you can add a preview by using the code below:




CODE
<div class="w-full">
@if (!empty($images))
@foreach ($images as $key => $image)
<div class="relative float-left pt-[10px] pl-[15px] pr-[10px] pb-[0px] h-[150px] mb-8">
<a class="absolute bg-[#ddd] p-[8px] right-[25px] top-[20%] rounded-[50%]" wire:click.prevent='removeItem({{ json_encode($key) }})'>
<i class="fa fa-trash text-red-600"></i>
</a>
<img src="{{ $image->temporaryUrl() }}" alt="" class="w-[150px] h-[150px] rounded-[15px]" />
</div>
@endforeach
@endif
</div>






The problem with the above code is that anytime you click on the input tag to select a new set of files, the previously selected one(s) is lost during the process. Here is the quick fix I provided using two of the lifecycle hooks in Livewire.



The first one is the updatingImages method. See the code sample below:




CODE
public function updatingImages($value) {
$this->prevImages = $this->images;
}






The above code is simply storing the content of the images property in $prevImages property while the $images property is about to start updating so as to prevent loss of content.



The second one is the updatedImages method. See the code sample below:




CODE
public function updatedImages($value) {
$this->images = array_merge($this->prevImages, $value);
}






The above code merges the data of the $prevImages property with the data of the newly selected image/images then stores it back into the $images property after the update is complete.



This is one of the simplest ways of solving the issue stated at the beginning of this article. I hope you find it helpful.



Thank you for reading!!!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Working with multiple image select in Laravel Livewire

Thematisch verwandte Begriffe: Working, with, multiple, image · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...