/ app / Http / Livewire / Eml / Remove.php
Remove.php
 1  <?php
 2  
 3  namespace App\Http\Livewire\Eml;
 4  
 5  use App\Http\Services\EMLService;
 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_eml_templates');
20      }
21  
22      public function remove()
23      {
24          $this->authorize('can_write_eml_templates');
25  
26          try {
27              EMLService::removeEMLTemplate($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(Index::class, 'refresh');
36  
37              $this->notification()->success(
38                  __('eml.template.notifications.remove.success.title'),
39                  __('eml.template.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.eml.remove');
52      }
53  }