Livewire

Building Image Gallery with Livewire v4

February 01, 2026 1 min read 20 views

Build an image gallery with lightbox.

Component

@php
new class extends Livewire\Component {
    public array $images = [];
    public ?int $activeIndex = null;
    
    public function open(int $index): void
    {
        $this->activeIndex = $index;
    }
    
    public function close(): void
    {
        $this->activeIndex = null;
    }
    
    public function next(): void
    {
        $this->activeIndex = ($this->activeIndex + 1) % count($this->images);
    }
    
    public function prev(): void
    {
        $this->activeIndex = ($this->activeIndex - 1 + count($this->images)) % count($this->images);
    }
}
@endphp
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!