33 lines
781 B
PHP
33 lines
781 B
PHP
<?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');
|
|
}
|
|
}
|