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

delete user #140

Open
Juanjosexdd opened this issue Dec 18, 2023 · 5 comments
Open

delete user #140

Juanjosexdd opened this issue Dec 18, 2023 · 5 comments

Comments

@Juanjosexdd
Copy link

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:

<button wire:click="destroy({{ $user->id }})">
      Eliminar
</button>
    public function destroy($userId)
    {
        $this->confirm('¿Estás seguro de que deseas eliminar este usuario?', [
            'showConfirmButton' => true,
            'confirmButtonText' => 'Si, Eliminar',
            'onConfirmed' => function() use ($userId) {
                $this->deleteUser($userId);
            }
        ]);
    }

    public function deleteUser($userId)
    {
        $user = User::find($this->userId);
        $user->delete();
        $this->alert('success', 'Usuario eliminado con éxito');
    }
@Kotzilla
Copy link

Kotzilla commented Jan 10, 2024

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');
}

@Juanjosexdd
Copy link
Author

Ya lo hice y nada..

@Kotzilla
Copy link

I was update code. Can you try again ?

@Juanjosexdd
Copy link
Author

no brother it doesn't work, I already tried it that way

@szajens
Copy link

szajens commented Feb 10, 2024

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');
  }
    
}

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

3 participants