user notifycations livewere laravel code example

Example: livewire notifications

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    public function render()
    { 
        return view('livewire.shared.my-component');
    }

    public function showModal()
    { 
        $this->emit('swal:modal', [
            'type'  => 'success',
            'title' => 'Success!!',
            'text'  => "This is a success message",
        ]);
    }

    public function showAlert()
    { 
        $this->emit('swal:alert', [
            'type'    => 'success',
            'title'   => 'This is a success alert!!', 
            'timeout' => 10000
        ]);
    }

    public function showConfirmation()
    { 
        $this->emit("swal:confirm", [
            'type'        => 'warning',
            'title'       => 'Are you sure?',
            'text'        => "You won't be able to revert this!",
            'confirmText' => 'Yes, delete!',
            'method'      => 'appointments:delete',
            'params'      => [], // optional, send params to success confirmation
            'callback'    => '', // optional, fire event if no confirmed
        ]);
    }
}

Tags:

Misc Example