Open szajens opened 4 months ago
Hello, perhaps in the next version, a function similar to the one I wrote yesterday could be added:
namespace App\Traits; use Jantinnerezo\LivewireAlert\LivewireAlert; use Livewire\Attributes\On; /** * Class Helper. */ trait Helper { use LivewireAlert; public function confirmMethod($method, $title, $text = null, $id = null){ $this->confirm($title, [ 'onConfirmed' => 'runMethod', 'data' => [ 'idFromConfirm' => $id, 'confirmMethod' => $method ], 'text' => $text, ]); } #[On('runMethod')] public function runMethod($data){ $id = $data['idFromConfirm']; $methodName = $data['confirmMethod']; if($id === null){ $this->{$methodName}(); } else { $this->{$methodName}($id); } }
How to use it in Blade?
<button wire:click="confirmMethod('delete', 'Do you want to delete?', '', $id)" >Run function</button>
This will execute $this->delete($id)
$this->delete($id)
No need to use protected $listeners = ['delete']; or #[On('delete')]
protected $listeners = ['delete']; or #[On('delete')]
Hello, perhaps in the next version, a function similar to the one I wrote yesterday could be added:
How to use it in Blade?
This will execute
$this->delete($id)
No need to use
protected $listeners = ['delete']; or #[On('delete')]