diff --git a/app/Http/Controllers/Company/RestoreAgentController.php b/app/Http/Controllers/Company/RestoreAgentController.php new file mode 100644 index 0000000..8384036 --- /dev/null +++ b/app/Http/Controllers/Company/RestoreAgentController.php @@ -0,0 +1,32 @@ +find($agentId); + $admin = CompanyAdmin::where('user_id', auth()->id()) + ->where( + 'company_id', + $agent->company_id + ); + if (!$admin->count()) + { + abort(404); + return; + } + if (!Agent::where('user_id', $agent->user->id)->count()) + { + $agent->restore(); + } + return to_route('company.agents.table'); + } +} diff --git a/app/Livewire/AgentsTable.php b/app/Livewire/AgentsTable.php index 3c0abe0..9088eff 100644 --- a/app/Livewire/AgentsTable.php +++ b/app/Livewire/AgentsTable.php @@ -36,4 +36,17 @@ public function render() ] ); } + public function dismiss($id) + { + to_route('company.agents.delete', [ + 'agent' => $id + ]); + } + + public function restore($id) + { + to_route('company.agents.restore', [ + 'agent' => $id + ]); + } } diff --git a/app/Models/Agent/Agent.php b/app/Models/Agent/Agent.php index 7ba37e8..28d83cd 100644 --- a/app/Models/Agent/Agent.php +++ b/app/Models/Agent/Agent.php @@ -43,12 +43,22 @@ protected static function booted(): void { static::created(function (Agent $agent) { - UserRole::create([ + UserRole::insertOrIgnore([ 'user_id' => $agent->user_id, 'role_id' => Role::AGENT ]); $agent->notify(); }); + + static::restored(function (Agent $agent) + { + UserRole::insertOrIgnore([ + 'user_id' => $agent->user_id, + 'role_id' => Role::AGENT + ]); + $agent->notify(); + }); + static::updated(function (Agent $agent) { if ($agent->trashed()) diff --git a/resources/views/livewire/agents-table.blade.php b/resources/views/livewire/agents-table.blade.php index 2971ac6..ade8222 100644 --- a/resources/views/livewire/agents-table.blade.php +++ b/resources/views/livewire/agents-table.blade.php @@ -18,7 +18,9 @@ @if (!$agent->trashed())