From 93a3f79f0c537db651f2373941f0a9604e70a28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Tue, 19 Sep 2023 20:13:11 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=D0=BE=D0=B2=D1=8B=D0?= =?UTF-8?q?=B9=20=D0=B4=D0=B2=D0=B8=D0=B6=D0=BE=D0=BA=20=D0=B2=20=D0=B0=D0=B4?= =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/EmployersController.php | 15 +++++++++-- .../Controllers/Admin/MsgAnswersController.php | 20 ++++++++++++++ app/Http/Controllers/Admin/UsersController.php | 12 ++++++--- app/Http/Controllers/Admin/WorkersController.php | 15 +++++++++-- resources/views/admin/employer/index.blade.php | 27 +------------------ resources/views/admin/find.blade.php | 28 ++++++++++++++++++++ resources/views/admin/users/index.blade.php | 27 +------------------ resources/views/admin/worker/index.blade.php | 27 +------------------ routes/web.php | 2 ++ 9 files changed, 88 insertions(+), 85 deletions(-) create mode 100644 resources/views/admin/find.blade.php 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') -
- -
-
-
-
- -
-
+ @include('admin.find') @endsection @section('content') diff --git a/resources/views/admin/find.blade.php b/resources/views/admin/find.blade.php new file mode 100644 index 0000000..989b336 --- /dev/null +++ b/resources/views/admin/find.blade.php @@ -0,0 +1,28 @@ +
+ +
+
+
+
+ +
+
diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 79c125e..4fd8766 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -43,32 +43,7 @@ @endsection @section('search') -
- -
-
-
-
- -
-
+ @include('admin.find') @endsection @section('content') diff --git a/resources/views/admin/worker/index.blade.php b/resources/views/admin/worker/index.blade.php index 3d30e4f..12c50a9 100644 --- a/resources/views/admin/worker/index.blade.php +++ b/resources/views/admin/worker/index.blade.php @@ -39,32 +39,7 @@ @endsection @section('search') -
- -
-
-
-
- -
-
+ @include('admin.find') @endsection @section('content') diff --git a/routes/web.php b/routes/web.php index 13a04f8..cdab12e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -155,6 +155,8 @@ Route::group([ Route::get('admin-messages', [MsgAnswersController::class, 'admin_messages'])->name('admin-messages'); // кабинет - сообщения (админские) Route::post('admin-messages', [MsgAnswersController::class, 'admin_messages_post'])->name('admin-messages-post'); + // кабинет - sql - конструкция запросов + Route::get('messages-sql', [MsgAnswersController::class, 'messages_sql'])->name('messages-sql'); /* * Расписанный подход в описании каждой директорий групп пользователей. -- 1.7.10.4