You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
899 B
39 lines
899 B
<?php
|
|
|
|
use App\Livewire\Concerns\WithToast;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component {
|
|
use WithToast;
|
|
|
|
#[Locked]
|
|
public string $model = '';
|
|
|
|
#[Locked]
|
|
public string $action = '';
|
|
|
|
#[Locked]
|
|
public string $keyName = 'id';
|
|
|
|
#[On('delete-data')]
|
|
public function delete(int|string $id): void
|
|
{
|
|
try {
|
|
if ($this->action === '') {
|
|
app($this->model)->where($this->keyName, $id)->delete();
|
|
} else {
|
|
$model = app($this->model)->where($this->keyName, $id)->first();
|
|
app($this->action)->execute($model);
|
|
}
|
|
$this->dispatch('delete-data-completed');
|
|
} catch (Exception $e) {
|
|
$this->dispatch('delete-data-failed', message: $e->getMessage());
|
|
}
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div>
|
|
</div>
|
|
|