PHP code example of jantinnerezo / livewire-alert

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/ */

    

jantinnerezo / livewire-alert example snippets

 bash
php artisan vendor:publish --tag=livewire-alert:assets
 php
use Jantinnerezo\LivewireAlert\LivewireAlert;
 
class Index extends Component
{
    use LivewireAlert;
    
    public function submit()
    {
        $this->alert('success', 'Basic Alert');
    }
}
 php
$this->alert('success', 'Success is approaching!');
 php
$this->alert('warning', 'The world has warned you.');
 php
$this->alert('info', 'The fact is you know your name :D');
 php
$this->alert('question', 'How are you today?');
 php
$this->alert('info', 'This is not as toast alert', [
    'toast' => false
]);
 php
$this->alert('info', 'Centering alert', [
    'position' => 'center'
]);
 php
$this->alert('question', 'How are you today?', [
    'showConfirmButton' => true
]);
 php
$this->alert('question', 'How are you today?', [
    'showConfirmButton' => true,
    'confirmButtonText' => 'Good'
]);
 php
public function confirmed()
{
    // Do something
}
 php
protected $listeners = [
    'confirmed'
];
 php
public function getListeners()
{
    return [
    	'confirmed'
    ];
}
 php
$this->alert('question', 'How are you today?', [
    'showConfirmButton' => true,
    'confirmButtonText' => 'Good',
    'onConfirmed' => 'confirmed' 
]);
 php
$this->alert('warning', 'Please enter password', [
    'showConfirmButton' => true,
    'confirmButtonText' => 'Submit',
    'onConfirmed' => 'confirmed',
    'input' => 'password',
    'inputValidator' => '(value) => new Promise((resolve) => '.
        '  resolve('.
        '    /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&]).{8,}$/.test(value) ?'.
        '    undefined : "Error in password"'.
        '  )'.
        ')',    
    'allowOutsideClick' => false,
    'timer' => null
]);
 php
public function denied() 
{
    // Do something when denied button is clicked
}
 php
public function getListeners()
{
    return [
    	'denied',
      'dismissed'
    ];
}
 php
$this->alert('warning', 'Alert with deny and cancel button', [
    'showDenyButton' => true,
    'denyButtonText' => 'Deny',
    'showCancelButton' => true,
    'cancelButtonText' => 'Cancel',
    'onDenied' => 'denied',
    'onDismissed' => 'cancelled'
]);
 PHP
'onConfirmed' => [
   'component' => 'livewire-component',
   'listener' => 'confirmed'
];
 php
$this->confirm('Are you sure do want to leave?', [
    'onConfirmed' => 'confirmed',
]);
 php
$this->flash('success', 'Successfully submitted form', [], '/');
 bash
php artisan vendor:publish --tag=livewire-alert:config
 php
[
    'alert' => [
        'position' => 'top-end',
        'timer' => 3000,
        'toast' => true,
        'text' => null,
        'showCancelButton' => false,
        'showConfirmButton' => false
    ],
    'confirm' => [
        'icon' => 'warning',
        'position' => 'center',
        'toast' => false,
        'timer' => null,
        'showConfirmButton' => true,
        'showCancelButton' => true,
        'cancelButtonText' => 'No',
        'confirmButtonColor' => '#3085d6',
        'cancelButtonColor' => '#d33'
    ]
]
 php
[
  'customClass' => [
    'container' => '',
    'popup' => '',
    'header' => '',
    'title' => '',
    'closeButton' => '',
    'icon' => '',
    'image' => '',
    'content' => '',
    'htmlContainer' => '',
    'input' => '',
    'inputLabel' => '',
    'validationMessage' => '',
    'actions' => '',
    'confirmButton' => '',
    'denyButton' => '',
    'cancelButton' => '',
    'loader' => '',
    'footer' => ''
   ]
];