Livewire Media Selector
Guide
Configuration
Livewire Integration
Performance
GitHub
Guide
Configuration
Livewire Integration
Performance
GitHub
  • Guide

    • Getting Started
    • Configuration Reference
    • Attribute Reference
    • Livewire Integration
    • Performance Playbook
    • Testing Recipes

Livewire Integration

The media selector ships as a Livewire 3 component and is optimized for parent-child data binding.

Using wire:model

<livewire:media-selector wire:model="postMedia" />

The component’s value property syncs with your parent component or Blade context.
When the modal closes with a confirmed selection, the payload updates automatically.

Interacting from a Livewire parent

class EditPost extends Component
{
    public array $postMedia = [];

    public function mount(Post $post): void
    {
        $this->postMedia = $post->getMediaPayload('gallery');
    }

    public function save(): void
    {
        $this->validate([
            'postMedia' => ['array'],
        ]);

        $this->post->syncMedia($this->postMedia, 'gallery');
    }
}

Listen for events

The component emits several events:

  • media-added
  • media-uploaded
  • media-deleted
  • media-restored
  • media-selected

Handling an event:

protected $listeners = [
    'media-selected' => 'handleMediaSelected',
];

public function handleMediaSelected($payload): void
{
    ray('Selected', $payload);
}

Accessing URLs directly

When rendering preview thumbnails outside the selector, use the trait helpers:

$post->getMediaUrl('gallery'); // first URL
$post->getMediaUrls('gallery'); // all URLs

This ensures cache-friendly lookups that respect eager-loaded relations and disk-specific URL generation.

Edit this page
Updated on: 11/12/25, 2:23 AM
Contributors: Pshtiwan Mahmood
Prev
Attribute Reference
Next
Performance Playbook