From d3fc274b19b550db8993a1a530c3fec9c22dfab9 Mon Sep 17 00:00:00 2001 From: anazaryan Date: Wed, 27 Nov 2024 14:03:28 +0400 Subject: [PATCH] users fixes --- app/Console/Commands/OptimizeUsers.php | 36 ++++++++++++++++++++++++ app/Http/Controllers/Admin/UsersController.php | 16 ++++++++++- app/Http/Controllers/CompanyController.php | 3 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/OptimizeUsers.php diff --git a/app/Console/Commands/OptimizeUsers.php b/app/Console/Commands/OptimizeUsers.php new file mode 100644 index 0000000..2ebbd4c --- /dev/null +++ b/app/Console/Commands/OptimizeUsers.php @@ -0,0 +1,36 @@ +delete(); + Worker::doesntHave('users')->delete(); + + } +} diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 88442cc..0222b99 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -46,7 +46,21 @@ class UsersController extends Controller } public function user_delete(User $user) { - $id = $user->delete(); + + $worker = $user->workers()->first(); + $employer = $user->employers()->first(); + + if ($worker) { + + $worker->delete(); + + } elseif ($employer) { + + $employer->delete(); + + } + + $user->delete(); return redirect()->route('admin.users')->with('Пользователь был удален из системы'); } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 158afda..49b914e 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -4,12 +4,13 @@ namespace App\Http\Controllers; use App\Models\Ad_employer; use App\Models\Employer; +use App\Models\User; use Illuminate\Http\Request; class CompanyController extends Controller { public function shipping_companies(Request $request) { - $emps = Employer::query()->with('ads')->where('status_hidden', '=', '0'); + $emps = Employer::query()->with('ads')->where('status_hidden', '=', '0')->whereHas('users'); if (($request->has('search')) && (!empty($request->get('search')))) { $search = $request->get('search'); $emps = $emps->where('name_company', 'LIKE', "%$search%"); -- 1.7.10.4