If you find PHPFlasher useful, we would greatly appreciate your support in the form of a star rating ⭐ on GitHub or by sharing the project on Twitter click here. Your feedback helps us keep the package up-to-date and well-maintained. Thank you


PHPFlasher offers a solid integration with Livewire v2.

Requirements

PHP >= 7.2 Laravel >= 7.0


Installation

Please follow the same installation steps as for the Laravel Installation package.


Usage

Dispatch notifications from your components

#/ livewire

namespace App\Http\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    public function save()
    {
        flash()->addInfo('Your account has been linked and a confirmation email has been sent.');
    }

    public function render()
    {
        return view('livewire.my_component');
    }

Events

For sweetalert you can listen to Confirmed, Denied and Dismissed from withing you component

#/ livewire events

namespace App\Http\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    protected $listeners = [
        'sweetalertConfirmed',
        'sweetalertDenied',
    ];

    public function delete()
    {
        sweetalert()
            ->showDenyButton()
            ->addInfo('confirm or deny action');
    }

    public function sweetalertConfirmed(array $payload)
    {
        toastr()->addSuccess('sweetalert was confirmed');
    }

    public function sweetalertDenied(array $payload)
    {
        toastr()->addError('sweetalert was denied');
    }

    public function render()
    {
        return view('livewire.my_component');
    }
}

If the name of the event and the method you’re calling match, you can leave out the key. For example: protected $listeners = ['sweetalertConfirmed']; will call the sweetalertConfirmed method when the sweetalertConfirmed event is emitted.

event handlers context

Every listener method accept an array $data parameter which contain the following data :

public function sweetalertConfirmed(array $payload)
{
    $promise = $payload['promise'];
    $envelope = $payload['envelope'];
}

promise : the resolved promise from sweetalert.

envelope : the notification where the event happened.

Younes

PHPFlasher is a project by Younes KHOUBZA.