jantinnerezo / livewire-alert

SweetAlert2 wrapper for Livewire
https://livewire-alert.jantinnerezo.com
MIT License
709 stars 73 forks source link

Take an ID as a parameter #132

Closed bar00ng closed 10 months ago

bar00ng commented 11 months ago

Hey I'm having trouble to passing an ID of my model to the onConfirmed function. can you guide me?? If u want i can provide you my code.

rickt96 commented 10 months ago

I've faced this issue too. When calling $this->alert() or $this->confirm() function, you can set in the third parameter $options a data array, like this:

$this->confirm("Are you sure?", [
    'onConfirmed' => "confirmed",
    'data' => [
        'post_id' => $postId
    ]
]);

Then, in the confirmed function handler:

public function confirmed($data)
{
    $postId = Arr::get($data, 'data.post_id', null);
    // other code
}
bar00ng commented 10 months ago

wow this is so useful bro!! thank you so much!!