Crud operation with same modal Livewire

1.1k views Asked by At

I'm using livewire for a new project so I want my crud operation with modal, in that case, I want to use one modal who responsible for creating and updating like vuejs. I try to do like this but this not work

In my blade

<form class="form" wire:submit.prevent="$editMode ? update : store">

In my component

public $editMode = false;

public function store() {
   $this->editMode = false;
   // code here
}

public function update() {
   $this->editMode = true;
   // code here
}

Livewire version: 2.x,

Can I achieve this Or do I have to use two modal for this? Thanks in advance

1

There are 1 answers

0
Qirel On BEST ANSWER

Your Livewire attributes cannot parse PHP, so you need to echo it out using blade. This will then re-render the component with the new submit method when you update the $editMode property in your Livewire component.

<form class="form" wire:submit.prevent="{{ $editMode ? 'update' : 'store' }}">
    <!-- The rest of the form -->
</form>