Jul 21, 2024
0
Level 1
Livewire sending multiple update request
Im trying to do crud operations and sending a message if operation was successful my code is working fine but when I run the operation I see in the network tab It sends multiple request to the server i'm using events to send messages to the front, I think is because of this code
protected function applySearch()
{
return User::where('user_id', 'like', '%' . strtoupper($this->search) . '%')
->orWhere('name', 'like', '%' . strtoupper($this->search) . '%')
->orWhere('email', 'like', '%' . strtoupper($this->search) . '%')
->paginate(5);
}
public function delete($user_id)
{
$this->user = \App\Models\User::where('user_id', $user_id)->first();
$this->user->delete();
$this->dispatch('userDeleted', 'User Deleted Successfully');
}
#[On(['userCreated', 'userUpdated', 'userDeleted'])]
public function render()
{
return view('livewire.user.user-index', [
'users' => $this->applySearch(),
]);
}
Please or to participate in this conversation.