/ app / Http / Livewire / Entities / Remove.php
Remove.php
 1  <?php
 2  
 3  namespace App\Http\Livewire\Entities;
 4  
 5  use App\Http\Services\EntityService;
 6  use Exception;
 7  use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 8  use Livewire\Component;
 9  use WireUi\Traits\Actions;
10  
11  class Remove extends Component
12  {
13      use AuthorizesRequests, Actions;
14  
15      public int $entityId = 0;
16  
17      public function mount()
18      {
19          $this->authorize('can_write_external_entities');
20      }
21  
22      public function remove()
23      {
24          $this->authorize('can_write_external_entities');
25  
26          try {
27              EntityService::remove($this->entityId);
28  
29              // UI Trick for delaying spinner
30              if (config('app.env') !== 'testing') {
31      sleep(1);
32  }
33  
34              $this->emitUp('closePanel');
35              $this->emitTo('entities.index', 'refresh');
36  
37              $this->notification()->success(
38                  __('entities.notifications.remove.success.title'),
39                  __('entities.notifications.remove.success.message')
40              );
41          } catch (Exception $e) {
42              $this->notification()->error(
43                  'Error',
44                  $e->getMessage()
45              );
46          }
47      }
48  
49      public function render()
50      {
51          return view('livewire.entities.remove');
52      }
53  }