Open Juanjosexdd opened 6 months ago
Change the code to this
public $userId;
protected $listeners = ['deleteUser'];
public function destroy($userId)
{
$this->userId = $userId;
$this->confirm('¿Estás seguro de que deseas eliminar este usuario?', [
'showConfirmButton' => true,
'confirmButtonText' => 'Si, Eliminar',
'onConfirmed' => 'deleteUser'
]);
}
public function deleteUser()
{
$user = User::find($this->userId);
$user->delete();
$this->alert('success', 'Usuario eliminado con éxito');
}
Ya lo hice y nada..
I was update code. Can you try again ?
no brother it doesn't work, I already tried it that way
use Livewire\Attributes\On;
class MenuList extends Component
{
use LivewireAlert;
public function destroy($userId)
{
$this->confirm('?Estás seguro de que deseas eliminar este usuario?', [
'showConfirmButton' => true,
'confirmButtonText' => 'Si, Eliminar',
'onConfirmed' => 'confirmed',
'data' => ['idToDelete' => $userId],
]);
}
#[On('confirmed')]
public function deleteUser($data)
{
$user = User::find($data['idToDelete']);
$user->delete();
$this->alert('success', 'Usuario eliminado con éxito');
}
}
I want to be able to delete a user's record, the alert works but the record is not being deleted when confirming, help.
view in component: