diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index 911d088..d407b63 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -21,11 +21,22 @@ class EmployersController extends Controller $user->update($request->all()); } - $users = User::where('is_worker', '0')->paginate(15); + $users = User::where('is_worker', '0'); + $find_key = ""; + if (isset($request->find)) { + $find_key = $request->find; + $users = $users->where(function($query) use($find_key) { + $query->Where('name', 'LIKE', "%$find_key%") + ->orWhere('email', 'LIKE', "%$find_key%") + ->orWhere('telephone', 'LIKE', "%$find_key%"); + }); + } + $users = $users->paginate(15); + if ($request->ajax()) { return view('admin.employer.index_ajax', compact('users')); } else { - return view('admin.employer.index', compact('users')); + return view('admin.employer.index', compact('users', 'find_key')); } } diff --git a/app/Http/Controllers/Admin/MsgAnswersController.php b/app/Http/Controllers/Admin/MsgAnswersController.php index 0123a74..cf60f60 100644 --- a/app/Http/Controllers/Admin/MsgAnswersController.php +++ b/app/Http/Controllers/Admin/MsgAnswersController.php @@ -7,6 +7,7 @@ use App\Models\Message; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; class MsgAnswersController extends Controller @@ -28,6 +29,25 @@ class MsgAnswersController extends Controller return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); } + public function messages_sql(Request $request) { + $id = Auth::user()->id; + DB::enableQueryLog(); + //$query = DB::select('select * from users where id = :id', ['id' => 1]); + $query = DB::select(DB::raw('SELECT u1.name as "To-user", u2.name as "From-user", m1.`text`, m1.created_at + FROM messages m1 + JOIN (SELECT MAX(id) id FROM messages + GROUP BY LEAST(user_id, to_user_id), + GREATEST(user_id, to_user_id) + ) m2 USING (id) + JOIN users u1 ON u1.id = m1.user_id + JOIN users u2 ON u2.id = m1.to_user_id + Where ((m1.user_id = :uid) or (m1.to_user_id = :uid2)) + '), ['uid' => $id, 'uid2' => $id]); + //dump(DB::getQueryLog()); + dd($query); + return; + } + public function admin_messages_post(Request $request) { $rules = [ 'title' => 'required|min:3|max:255', diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 57bbbd3..cec8581 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -17,13 +17,19 @@ class UsersController extends Controller $request->offsetUnset('id'); $user->update($request->all()); } - - $users = User::query()->paginate(15); + $find_key = ""; + $users = User::query(); + if (isset($request->find)) { + $find_key = $request->find; + $users = $users->where('name', 'LIKE', "%$find_key%") + ->orWhere('email', 'LIKE', "%$find_key%"); + } + $users = $users->paginate(15); if ($request->ajax()) { return view('admin.users.index_ajax', compact('users', 'id_admin')); } else { - return view('admin.users.index', compact('users', 'title', 'id_admin')); + return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key')); } } diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php index 1ae26aa..bcca5ca 100644 --- a/app/Http/Controllers/Admin/WorkersController.php +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -17,12 +17,23 @@ class WorkersController extends Controller $user->update($request->all()); } - $users = User::where('is_worker', '1')->paginate(15); + $users = User::where('is_worker', '1'); + $find_key = ""; + if (isset($request->find)) { + $find_key = $request->find; + $users = $users->where(function($query) use($find_key) { + $query->Where('name_man', 'LIKE', "%$find_key%") + ->orWhere('email', 'LIKE', "%$find_key%") + ->orWhere('telephone', 'LIKE', "%$find_key%"); + }); + } + + $users = $users->paginate(15); if ($request->ajax()) { return view('admin.worker.index_ajax', compact('users')); } else { - return view('admin.worker.index', compact('users')); + return view('admin.worker.index', compact('users', 'find_key')); } } diff --git a/resources/views/admin/employer/index.blade.php b/resources/views/admin/employer/index.blade.php index 5471ebb..248eefc 100644 --- a/resources/views/admin/employer/index.blade.php +++ b/resources/views/admin/employer/index.blade.php @@ -39,32 +39,7 @@ @endsection @section('search') -