Commit d3fc274b19b550db8993a1a530c3fec9c22dfab9

Authored by Hayk Nazaryan
1 parent b57da04555
Exists in master

users fixes

Showing 3 changed files with 53 additions and 2 deletions Side-by-side Diff

app/Console/Commands/OptimizeUsers.php
... ... @@ -0,0 +1,36 @@
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Employer;
  6 +use App\Models\Worker;
  7 +use Illuminate\Console\Command;
  8 +
  9 +class OptimizeUsers extends Command
  10 +{
  11 + /**
  12 + * The name and signature of the console command.
  13 + *
  14 + * @var string
  15 + */
  16 + protected $signature = 'optimize:users';
  17 +
  18 + /**
  19 + * The console command description.
  20 + *
  21 + * @var string
  22 + */
  23 + protected $description = 'Command description';
  24 +
  25 + /**
  26 + * Execute the console command.
  27 + *
  28 + * @return int
  29 + */
  30 + public function handle()
  31 + {
  32 + Employer::doesntHave('users')->delete();
  33 + Worker::doesntHave('users')->delete();
  34 +
  35 + }
  36 +}
app/Http/Controllers/Admin/UsersController.php
... ... @@ -46,7 +46,21 @@ class UsersController extends Controller
46 46 }
47 47  
48 48 public function user_delete(User $user) {
49   - $id = $user->delete();
  49 +
  50 + $worker = $user->workers()->first();
  51 + $employer = $user->employers()->first();
  52 +
  53 + if ($worker) {
  54 +
  55 + $worker->delete();
  56 +
  57 + } elseif ($employer) {
  58 +
  59 + $employer->delete();
  60 +
  61 + }
  62 +
  63 + $user->delete();
50 64  
51 65 return redirect()->route('admin.users')->with('Пользователь был удален из системы');
52 66 }
app/Http/Controllers/CompanyController.php
... ... @@ -4,12 +4,13 @@ namespace App\Http\Controllers;
4 4  
5 5 use App\Models\Ad_employer;
6 6 use App\Models\Employer;
  7 +use App\Models\User;
7 8 use Illuminate\Http\Request;
8 9  
9 10 class CompanyController extends Controller
10 11 {
11 12 public function shipping_companies(Request $request) {
12   - $emps = Employer::query()->with('ads')->where('status_hidden', '=', '0');
  13 + $emps = Employer::query()->with('ads')->where('status_hidden', '=', '0')->whereHas('users');
13 14 if (($request->has('search')) && (!empty($request->get('search')))) {
14 15 $search = $request->get('search');
15 16 $emps = $emps->where('name_company', 'LIKE', "%$search%");