agents restore added
This commit is contained in:
parent
2154ca1bec
commit
2c5dcebc84
32
app/Http/Controllers/Company/RestoreAgentController.php
Normal file
32
app/Http/Controllers/Company/RestoreAgentController.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Company;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Company\CompanyAdmin;
|
||||
use App\Models\Agent\Agent;
|
||||
use App\Models\User;
|
||||
|
||||
class RestoreAgentController extends Controller
|
||||
{
|
||||
public function __invoke($agentId)
|
||||
{
|
||||
$agent = Agent::withTrashed()->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');
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
</td>
|
||||
@if (!$agent->trashed())
|
||||
<td class="align-middle text-center bg-white">
|
||||
<a class="btn" href="{{ route('company.agents.delete', ['agent' => $agent->id]) }}">
|
||||
<a class="btn"
|
||||
wire:confirm = "Выбранный агент потеряет доступ к личному кабинету и больше не сможет создавать новые контакты.\nПродолжить?"
|
||||
wire:click = "dismiss({{ $agent->id }})">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"
|
||||
fill="currentColor" class="bi bi-person-dash" viewBox="0 0 16 16">
|
||||
<path
|
||||
@ -31,6 +33,13 @@
|
||||
@else
|
||||
<td class="align-middle">
|
||||
{{ $agent->deleted_at->diffForHumans() }}
|
||||
<div>
|
||||
<a style="text-decoration: underline dotted;" href="#"
|
||||
wire:confirm = "Выбранный агент сможет создавать новые контакты.\nПродолжить?"
|
||||
wire:click = "restore({{ $agent->id }})">
|
||||
Восстановить
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@ -41,4 +50,22 @@
|
||||
<div class="mt-3">
|
||||
{{ $agents->links('layouts.pagination') }}
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Подтвердите действие</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Выбранный агент потеряет доступ к личному кабинету и больше не сможет создавать новые контакты.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||
<button type="button" class="btn btn-danger">Продолжить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -45,6 +45,8 @@
|
||||
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
||||
Route::post('/company/agents/store/', App\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
||||
Route::get('/company/agents/{agent}/delete', App\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
|
||||
Route::get('/company/agents/{agent}/restore', App\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
||||
|
||||
});
|
||||
|
||||
//МАКЕТЫ
|
||||
|
||||
Loading…
Reference in New Issue
Block a user