1. Go to this page and download the library: Download rishadblack/wire-modals library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rishadblack / wire-modals example snippets
class NoteEdit extends Component
{
use WithModals;
#[ModalAction(default: true)]
public function openNoteModal(array $data = []): void
{
$this->note = Note::findOrFail($data['id']);
$this->modalOpen('NoteModal');
}
}
namespace App\Livewire\Modals;
use App\Models\Note;
use Livewire\Attributes\Locked;
use Livewire\Component;
use Rishadblack\WireModals\Attributes\ModalAction;
use Rishadblack\WireModals\Traits\WithModals;
class NoteEdit extends Component
{
use WithModals;
#[Locked]
public ?int $note_id = null;
public string $title = '';
/**
* @param array{id: int|string|null, data: array<string, string>} $data
*/
#[ModalAction(default: true)]
public function openNoteModal(array $data = []): void
{
$this->reset('note_id', 'title');
if (! empty($data['id'])) {
$note = Note::findOrFail($data['id']);
$this->note_id = $note->id;
$this->title = $note->title;
}
$this->modalOpen('NoteModal');
}
public function save(): void
{
$this->validate(['title' => ['
public function openOptionsModal(): void
{
$this->modalOpen('OptionsModal', keepComponent: true);
}
#[ModalAction(default: true)]
public function openStepOneModal(array $data = []): void
{
$this->modalOpen('StepOneModal'); // owns the component
}
public function openStepTwoModal(): void
{
$this->validate(['name' => ['ckToStepTwo(): void
{
$this->modalClose('StepThreeModal'); // reveals step two again
}
public function finish(): void
{
$this->dispatch('wizard-finished', name: $this->name);
$this->closeComponent(); // hides all three, then unmounts
}
// TagPicker
public function pick(string $tag): void
{
$this->dispatch('tag-picked', tag: $tag)->to('modals.note-edit');
$this->closeComponent();
}
// NoteEdit
#[On('tag-picked')]
public function addTag(string $tag): void { /* ... */ }
#[ModalAction]
public function noteDelete(array $data = []): void
{
$this->note_id = Note::findOrFail($data['id'])->id;
$this->modalOpen('DeleteModal');
}
public function confirmDelete(): void
{
Note::whereKey($this->note_id)->delete();
$this->dispatch('notes-changed');
$this->closeComponent();
}
protected function authorizeModalAction(string $action, array $payload): bool
{
return match ($action) {
'noteDelete' => auth()->user()->can('notes.delete'),
default => auth()->user()->can('notes.update'),
};
}