Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add new functionality #146

Open
szajens opened this issue Feb 28, 2024 · 0 comments
Open

Please add new functionality #146

szajens opened this issue Feb 28, 2024 · 0 comments

Comments

@szajens
Copy link

szajens commented Feb 28, 2024

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)

No need to use protected $listeners = ['delete']; or #[On('delete')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant