/ app / Http / Livewire / Users / Restore.php
Restore.php
 1  <?php
 2  
 3  namespace App\Http\Livewire\Users;
 4  
 5  use App\Http\Services\UserService;
 6  use Exception;
 7  use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 8  use Livewire\Component;
 9  use WireUi\Traits\Actions;
10  
11  class Restore extends Component
12  {
13      use AuthorizesRequests, Actions;
14  
15      public int $entityId = 0;
16  
17      public function mount()
18      {
19          $this->authorize('can_write_users');
20      }
21  
22      public function restore()
23      {
24          $this->authorize('can_write_users');
25  
26          try {
27              UserService::restore($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->emit('userRestored');
36  
37              $this->notification()->success(
38                  __('users.notifications.restore.success.title'),
39                  __('users.notifications.restore.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.users.restore');
52      }
53  }