1. Go to this page and download the library: Download jantinnerezo/livewire-alert 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/ */
php
LivewireAlert::title('Save?')
->withConfirmButton('Save')
->onConfirm('saveData', ['id' => $this->itemId])
->show();
public function saveData($data)
{
$itemId = $data['id'];
// Save logic
}
php
LivewireAlert::title('Delete?')
->withConfirmButton('Delete')
->withCancelButton('Keep')
->onDismiss('cancelDelete', ['id' => $this->itemId])
->show();
public function cancelDelete($data)
{
$itemId = $data['id'];
// Cancel logic
}
php
LivewireAlert::title('Update?')
->withConfirmButton('Update')
->withDenyButton('Discard')
->onDeny('discardChanges', ['id' => $this->itemId])
->show();
public function discardChanges($data)
{
$itemId = $data['id'];
// Discard logic
}
php
LivewireAlert::title('Process File')
->text('What would you like to do?')
->question()
->withConfirmButton('Save')
->withCancelButton('Cancel')
->withDenyButton('Delete')
->onConfirm('saveFile', ['id' => $this->fileId])
->onDeny('deleteFile', ['id' => $this->fileId])
->onDismiss('cancelAction', ['id' => $this->fileId])
->show();
php
LivewireAlert::title('Delete Item')
->text('Are you sure you want to delete this item?')
->asConfirm()
->onConfirm('deleteItem', ['id' => $this->itemId])
->onDeny('keepItem', ['id' => $this->itemId])
->show();
public function deleteItem($data)
{
$itemId = $data['id'];
// Delete logic
}
public function keepItem($data)
{
$itemId = $data['id'];
// Keep logic
}
php
LivewireAlert::title('Enter Your Name')
->withOptions([
'input' => 'text',
'inputPlaceholder' => 'Your name here',
])
->withConfirmButton('Submit')
->onConfirm('saveName')
->show();
public function saveName($data)
{
$name = $data['value']; // User’s input from the text field
// Save the name
}
php
LivewireAlert::title('Choose an Option')
->withOptions([
'input' => 'select',
'inputOptions' => [
'small' => 'Small',
'medium' => 'Medium',
'large' => 'Large',
],
'inputPlaceholder' => 'Select a size',
])
->withConfirmButton('Confirm')
->onConfirm('processSelection')
->show();
public function processSelection($data)
{
$size = $data['value']; // Selected value (e.g., 'small')
// Process the selection
}
php
public function mount()
{
if (session()->has('saved')) {
LivewireAlert::title(session('saved.title'))
->text(session('saved.text'))
->success()
->show();
}
}
public function changesSaved()
{
session()->flash('saved', [
'title' => 'Changes Saved!',
'text' => 'You can safely close the tab!',
]);
$this->redirect('/dashboard');
}
php
use Jantinnerezo\LivewireAlert\LivewireAlert;
public function save(LivewireAlert $alert)
{
$alert->title('Success!')
->text('What would you like to do?')
->question()
->withConfirmButton('Save')
->withCancelButton('Cancel')
->withDenyButton('Delete')
->onConfirm('saveFile', ['id' => $this->fileId])
->onDeny('deleteFile', ['id' => $this->fileId])
->onDismiss('cancelAction', ['id' => $this->fileId])
->show();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.