Commit 93a3f79f0c537db651f2373941f0a9604e70a28f
1 parent
e688e0d8a7
Exists in
master
and in
1 other branch
Поисковый движок в админке
Showing 9 changed files with 88 additions and 85 deletions Side-by-side Diff
- app/Http/Controllers/Admin/EmployersController.php
- app/Http/Controllers/Admin/MsgAnswersController.php
- app/Http/Controllers/Admin/UsersController.php
- app/Http/Controllers/Admin/WorkersController.php
- resources/views/admin/employer/index.blade.php
- resources/views/admin/find.blade.php
- resources/views/admin/users/index.blade.php
- resources/views/admin/worker/index.blade.php
- routes/web.php
app/Http/Controllers/Admin/EmployersController.php
... | ... | @@ -21,11 +21,22 @@ class EmployersController extends Controller |
21 | 21 | $user->update($request->all()); |
22 | 22 | } |
23 | 23 | |
24 | - $users = User::where('is_worker', '0')->paginate(15); | |
24 | + $users = User::where('is_worker', '0'); | |
25 | + $find_key = ""; | |
26 | + if (isset($request->find)) { | |
27 | + $find_key = $request->find; | |
28 | + $users = $users->where(function($query) use($find_key) { | |
29 | + $query->Where('name', 'LIKE', "%$find_key%") | |
30 | + ->orWhere('email', 'LIKE', "%$find_key%") | |
31 | + ->orWhere('telephone', 'LIKE', "%$find_key%"); | |
32 | + }); | |
33 | + } | |
34 | + $users = $users->paginate(15); | |
35 | + | |
25 | 36 | if ($request->ajax()) { |
26 | 37 | return view('admin.employer.index_ajax', compact('users')); |
27 | 38 | } else { |
28 | - return view('admin.employer.index', compact('users')); | |
39 | + return view('admin.employer.index', compact('users', 'find_key')); | |
29 | 40 | } |
30 | 41 | } |
31 | 42 |
app/Http/Controllers/Admin/MsgAnswersController.php
... | ... | @@ -7,6 +7,7 @@ use App\Models\Message; |
7 | 7 | use App\Models\User; |
8 | 8 | use Illuminate\Http\Request; |
9 | 9 | use Illuminate\Support\Facades\Auth; |
10 | +use Illuminate\Support\Facades\DB; | |
10 | 11 | use Illuminate\Support\Facades\Validator; |
11 | 12 | |
12 | 13 | class MsgAnswersController extends Controller |
... | ... | @@ -28,6 +29,25 @@ class MsgAnswersController extends Controller |
28 | 29 | return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); |
29 | 30 | } |
30 | 31 | |
32 | + public function messages_sql(Request $request) { | |
33 | + $id = Auth::user()->id; | |
34 | + DB::enableQueryLog(); | |
35 | + //$query = DB::select('select * from users where id = :id', ['id' => 1]); | |
36 | + $query = DB::select(DB::raw('SELECT u1.name as "To-user", u2.name as "From-user", m1.`text`, m1.created_at | |
37 | + FROM messages m1 | |
38 | + JOIN (SELECT MAX(id) id FROM messages | |
39 | + GROUP BY LEAST(user_id, to_user_id), | |
40 | + GREATEST(user_id, to_user_id) | |
41 | + ) m2 USING (id) | |
42 | + JOIN users u1 ON u1.id = m1.user_id | |
43 | + JOIN users u2 ON u2.id = m1.to_user_id | |
44 | + Where ((m1.user_id = :uid) or (m1.to_user_id = :uid2)) | |
45 | + '), ['uid' => $id, 'uid2' => $id]); | |
46 | + //dump(DB::getQueryLog()); | |
47 | + dd($query); | |
48 | + return; | |
49 | + } | |
50 | + | |
31 | 51 | public function admin_messages_post(Request $request) { |
32 | 52 | $rules = [ |
33 | 53 | 'title' => 'required|min:3|max:255', |
app/Http/Controllers/Admin/UsersController.php
... | ... | @@ -17,13 +17,19 @@ class UsersController extends Controller |
17 | 17 | $request->offsetUnset('id'); |
18 | 18 | $user->update($request->all()); |
19 | 19 | } |
20 | - | |
21 | - $users = User::query()->paginate(15); | |
20 | + $find_key = ""; | |
21 | + $users = User::query(); | |
22 | + if (isset($request->find)) { | |
23 | + $find_key = $request->find; | |
24 | + $users = $users->where('name', 'LIKE', "%$find_key%") | |
25 | + ->orWhere('email', 'LIKE', "%$find_key%"); | |
26 | + } | |
27 | + $users = $users->paginate(15); | |
22 | 28 | |
23 | 29 | if ($request->ajax()) { |
24 | 30 | return view('admin.users.index_ajax', compact('users', 'id_admin')); |
25 | 31 | } else { |
26 | - return view('admin.users.index', compact('users', 'title', 'id_admin')); | |
32 | + return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key')); | |
27 | 33 | } |
28 | 34 | } |
29 | 35 |
app/Http/Controllers/Admin/WorkersController.php
... | ... | @@ -17,12 +17,23 @@ class WorkersController extends Controller |
17 | 17 | $user->update($request->all()); |
18 | 18 | } |
19 | 19 | |
20 | - $users = User::where('is_worker', '1')->paginate(15); | |
20 | + $users = User::where('is_worker', '1'); | |
21 | + $find_key = ""; | |
22 | + if (isset($request->find)) { | |
23 | + $find_key = $request->find; | |
24 | + $users = $users->where(function($query) use($find_key) { | |
25 | + $query->Where('name_man', 'LIKE', "%$find_key%") | |
26 | + ->orWhere('email', 'LIKE', "%$find_key%") | |
27 | + ->orWhere('telephone', 'LIKE', "%$find_key%"); | |
28 | + }); | |
29 | + } | |
30 | + | |
31 | + $users = $users->paginate(15); | |
21 | 32 | |
22 | 33 | if ($request->ajax()) { |
23 | 34 | return view('admin.worker.index_ajax', compact('users')); |
24 | 35 | } else { |
25 | - return view('admin.worker.index', compact('users')); | |
36 | + return view('admin.worker.index', compact('users', 'find_key')); | |
26 | 37 | } |
27 | 38 | } |
28 | 39 |
resources/views/admin/employer/index.blade.php
... | ... | @@ -39,32 +39,7 @@ |
39 | 39 | @endsection |
40 | 40 | |
41 | 41 | @section('search') |
42 | - <div class="absolute inset-y-0 flex items-center pl-2"> | |
43 | - <svg | |
44 | - class="w-4 h-4" | |
45 | - aria-hidden="true" | |
46 | - fill="currentColor" | |
47 | - viewBox="0 0 20 20" | |
48 | - > | |
49 | - <path | |
50 | - fill-rule="evenodd" | |
51 | - d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" | |
52 | - clip-rule="evenodd" | |
53 | - ></path> | |
54 | - </svg> | |
55 | - </div> | |
56 | - <form action="" method="POST"> | |
57 | - <div style="float:left;"><input | |
58 | - class="w-full pl-8 pr-2 text-sm text-gray-700 placeholder-gray-600 bg-gray-100 border-0 rounded-md dark:placeholder-gray-500 dark:focus:shadow-outline-gray dark:focus:placeholder-gray-600 dark:bg-gray-700 dark:text-gray-200 focus:placeholder-gray-500 focus:bg-white focus:border-purple-300 focus:outline-none focus:shadow-outline-purple form-input" | |
59 | - style="width: 400px" | |
60 | - type="text" | |
61 | - placeholder="Искать..." | |
62 | - aria-label="Search" | |
63 | - /></div> | |
64 | - <div style="float: left"> | |
65 | - <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Искать</button> | |
66 | - </div> | |
67 | - </form> | |
42 | + @include('admin.find') | |
68 | 43 | @endsection |
69 | 44 | |
70 | 45 | @section('content') |
resources/views/admin/find.blade.php
... | ... | @@ -0,0 +1,28 @@ |
1 | +<div class="absolute inset-y-0 flex items-center pl-2"> | |
2 | + <svg | |
3 | + class="w-4 h-4" | |
4 | + aria-hidden="true" | |
5 | + fill="currentColor" | |
6 | + viewBox="0 0 20 20" | |
7 | + > | |
8 | + <path | |
9 | + fill-rule="evenodd" | |
10 | + d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" | |
11 | + clip-rule="evenodd" | |
12 | + ></path> | |
13 | + </svg> | |
14 | +</div> | |
15 | +<form action="" method="GET"> | |
16 | + <div style="float:left;"><input | |
17 | + name="find" id="find" | |
18 | + class="w-full pl-8 pr-2 text-sm text-gray-700 placeholder-gray-600 bg-gray-100 border-0 rounded-md dark:placeholder-gray-500 dark:focus:shadow-outline-gray dark:focus:placeholder-gray-600 dark:bg-gray-700 dark:text-gray-200 focus:placeholder-gray-500 focus:bg-white focus:border-purple-300 focus:outline-none focus:shadow-outline-purple form-input" | |
19 | + style="width: 400px" | |
20 | + type="text" | |
21 | + placeholder="Искать..." | |
22 | + aria-label="Search" | |
23 | + value="{{$find_key}}" | |
24 | + /></div> | |
25 | + <div style="float: left"> | |
26 | + <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Искать</button> | |
27 | + </div> | |
28 | +</form> |
resources/views/admin/users/index.blade.php
... | ... | @@ -43,32 +43,7 @@ |
43 | 43 | @endsection |
44 | 44 | |
45 | 45 | @section('search') |
46 | - <div class="absolute inset-y-0 flex items-center pl-2"> | |
47 | - <svg | |
48 | - class="w-4 h-4" | |
49 | - aria-hidden="true" | |
50 | - fill="currentColor" | |
51 | - viewBox="0 0 20 20" | |
52 | - > | |
53 | - <path | |
54 | - fill-rule="evenodd" | |
55 | - d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" | |
56 | - clip-rule="evenodd" | |
57 | - ></path> | |
58 | - </svg> | |
59 | - </div> | |
60 | - <form action="" method="POST"> | |
61 | - <div style="float:left;"><input | |
62 | - class="w-full pl-8 pr-2 text-sm text-gray-700 placeholder-gray-600 bg-gray-100 border-0 rounded-md dark:placeholder-gray-500 dark:focus:shadow-outline-gray dark:focus:placeholder-gray-600 dark:bg-gray-700 dark:text-gray-200 focus:placeholder-gray-500 focus:bg-white focus:border-purple-300 focus:outline-none focus:shadow-outline-purple form-input" | |
63 | - style="width: 400px" | |
64 | - type="text" | |
65 | - placeholder="Искать..." | |
66 | - aria-label="Search" | |
67 | - /></div> | |
68 | - <div style="float: left"> | |
69 | - <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Искать</button> | |
70 | - </div> | |
71 | - </form> | |
46 | + @include('admin.find') | |
72 | 47 | @endsection |
73 | 48 | |
74 | 49 | @section('content') |
resources/views/admin/worker/index.blade.php
... | ... | @@ -39,32 +39,7 @@ |
39 | 39 | @endsection |
40 | 40 | |
41 | 41 | @section('search') |
42 | - <div class="absolute inset-y-0 flex items-center pl-2"> | |
43 | - <svg | |
44 | - class="w-4 h-4" | |
45 | - aria-hidden="true" | |
46 | - fill="currentColor" | |
47 | - viewBox="0 0 20 20" | |
48 | - > | |
49 | - <path | |
50 | - fill-rule="evenodd" | |
51 | - d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" | |
52 | - clip-rule="evenodd" | |
53 | - ></path> | |
54 | - </svg> | |
55 | - </div> | |
56 | - <form action="" method="POST"> | |
57 | - <div style="float:left;"><input | |
58 | - class="w-full pl-8 pr-2 text-sm text-gray-700 placeholder-gray-600 bg-gray-100 border-0 rounded-md dark:placeholder-gray-500 dark:focus:shadow-outline-gray dark:focus:placeholder-gray-600 dark:bg-gray-700 dark:text-gray-200 focus:placeholder-gray-500 focus:bg-white focus:border-purple-300 focus:outline-none focus:shadow-outline-purple form-input" | |
59 | - style="width: 400px" | |
60 | - type="text" | |
61 | - placeholder="Искать..." | |
62 | - aria-label="Search" | |
63 | - /></div> | |
64 | - <div style="float: left"> | |
65 | - <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Искать</button> | |
66 | - </div> | |
67 | - </form> | |
42 | + @include('admin.find') | |
68 | 43 | @endsection |
69 | 44 | |
70 | 45 | @section('content') |
routes/web.php
... | ... | @@ -155,6 +155,8 @@ Route::group([ |
155 | 155 | Route::get('admin-messages', [MsgAnswersController::class, 'admin_messages'])->name('admin-messages'); |
156 | 156 | // кабинет - сообщения (админские) |
157 | 157 | Route::post('admin-messages', [MsgAnswersController::class, 'admin_messages_post'])->name('admin-messages-post'); |
158 | + // кабинет - sql - конструкция запросов | |
159 | + Route::get('messages-sql', [MsgAnswersController::class, 'messages_sql'])->name('messages-sql'); | |
158 | 160 | |
159 | 161 | /* |
160 | 162 | * Расписанный подход в описании каждой директорий групп пользователей. |