I’m trying to close modal bootstrap:
my code of update user:
public function updateUser($id)
{
$data = $this->validate([
'name' => ['required','string','max:100'],
'email' => ['required','email',
Rule::unique('users')->ignore($id),
],
'password' => ['sometimes','nullable','min:6'],
]);
if($this->password){
$data['password'] = bcrypt($this->password);
}
User::where('id',$id)->update($data);
$this->emit('userUpdated');
$this->dispatchBrowserEvent('userUpdated', "$id");
}
First, try JS Code
<script>
window.livewire.on('userUpdated', id => {
alert('A user was updated with the id of: ' + id);
})
</script>
Second try js Code:
window.livewire.on('userUpdated', function(userId){
alert('A user was updated with the id of: ' + userId);
});
I got an error in both and the error in the alert is
A user was added with the id of: undefined
How can I get to user id to close my modal ?!