Commit a89ff088a2ae8caff3d748b0b7aedb481bc78884
1 parent
3e44ec5151
Exists in
master
and in
1 other branch
Поисковая система в сообщениях админки
Showing 7 changed files with 199 additions and 39 deletions Side-by-side Diff
app/Http/Controllers/Admin/MsgAnswersController.php
... | ... | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; |
5 | 5 | use App\Http\Controllers\Controller; |
6 | 6 | use App\Models\Message; |
7 | 7 | use App\Models\User; |
8 | +use Illuminate\Database\Eloquent\Builder; | |
8 | 9 | use Illuminate\Http\Request; |
9 | 10 | use Illuminate\Support\Facades\Auth; |
10 | 11 | use Illuminate\Support\Facades\DB; |
... | ... | @@ -12,10 +13,88 @@ use Illuminate\Support\Facades\Validator; |
12 | 13 | |
13 | 14 | class MsgAnswersController extends Controller |
14 | 15 | { |
15 | - public function messages() { | |
16 | - $Msgs = Message::with('user_from')->with('user_to')->with('response')->orderByDesc('created_at')->paginate(25); | |
16 | + public function messages(Request $request) { | |
17 | + $find_key = ""; | |
18 | + $find_cat = ""; | |
19 | + $Msgs = Message::with('user_from')->with('user_to')->with('response'); | |
20 | + | |
21 | + $Msgs = $this->filter($Msgs, $request, $find_key, $find_cat); | |
22 | + | |
23 | + $Msgs = $Msgs->orderByDesc('created_at')->paginate(25); | |
24 | + | |
25 | + return view('admin.messages', compact('Msgs', 'find_key', 'find_cat')); | |
26 | + } | |
27 | + | |
28 | + public function read_message(Message $message) { | |
29 | + return view('admin.message-read', compact('message')); | |
30 | + } | |
31 | + | |
32 | + public function filter($Msgs, Request $request, &$find_key, &$find_cat) { | |
33 | + if (isset($request->find)) { | |
34 | + $find_key = $request->find; | |
35 | + $Msgs = $Msgs->where(function($q) use ($find_key) { | |
36 | + $q->whereHas('user_from', | |
37 | + function (Builder $query) use ($find_key) { | |
38 | + $query->where('name', 'LIKE', "%$find_key%"); | |
39 | + } | |
40 | + )-> | |
41 | + orWhereHas('user_to', | |
42 | + function (Builder $query) use ($find_key) { | |
43 | + $query->where('name', 'LIKE', "%$find_key%"); | |
44 | + } | |
45 | + ); | |
46 | + }); | |
47 | + } | |
48 | + | |
49 | + if (isset($request->category)) { | |
50 | + $find_cat = $request->category; | |
51 | + | |
52 | + switch ($find_cat) { | |
53 | + case 'Работодатели': | |
54 | + $Msgs = $Msgs->where(function($q) { | |
55 | + $q->whereHas('user_to', | |
56 | + function (Builder $query) { | |
57 | + $query->where('is_worker', '0'); | |
58 | + } | |
59 | + )->orwhereHas('user_from', | |
60 | + function (Builder $query) { | |
61 | + $query->where('is_worker', '0'); | |
62 | + } | |
63 | + ); | |
64 | + }); | |
65 | + break; | |
66 | + case 'Соискатели': | |
67 | + $Msgs = $Msgs->where(function($q) { | |
68 | + $q->whereHas('user_to', | |
69 | + function (Builder $query) { | |
70 | + $query->where('is_worker', '1'); | |
71 | + } | |
72 | + )->orwhereHas('user_from', | |
73 | + function (Builder $query) { | |
74 | + $query->where('is_worker', '1'); | |
75 | + } | |
76 | + ); | |
77 | + }); | |
78 | + break; | |
79 | + case 'Администраторы': | |
80 | + $Msgs = $Msgs->where(function($q) { | |
81 | + $q->whereHas('user_to', | |
82 | + function (Builder $query) { | |
83 | + $query->where('admin', '1'); | |
84 | + } | |
85 | + )->orwhereHas('user_from', | |
86 | + function (Builder $query) { | |
87 | + $query->where('admin', '1'); | |
88 | + } | |
89 | + ); | |
90 | + }); | |
91 | + break; | |
92 | + default:break; | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + return $Msgs; | |
17 | 97 | |
18 | - return view('admin.messages', compact('Msgs')); | |
19 | 98 | } |
20 | 99 | |
21 | 100 | public function admin_messages(Request $request) { |
... | ... | @@ -29,14 +108,22 @@ class MsgAnswersController extends Controller |
29 | 108 | $users = User::query()->OrderBy('name')->get(); |
30 | 109 | |
31 | 110 | $Msgs = Message::with('user_from')->with('user_to')->with('response') |
32 | - ->where('user_id', '=', $id_admin) | |
33 | - ->orWhere('to_user_id', '=', $id_admin) | |
34 | - ->orderByDesc('created_at')->paginate(5); | |
111 | + ->where(function($query) use ($id_admin) { | |
112 | + $query->where('user_id', '=', $id_admin) | |
113 | + ->orWhere('to_user_id', '=', $id_admin); | |
114 | + }); | |
115 | + | |
116 | + $find_key = ''; | |
117 | + $find_cat = ''; | |
118 | + | |
119 | + $Msgs = $this->filter($Msgs, $request, $find_key, $find_cat); | |
120 | + | |
121 | + $Msgs = $Msgs->orderByDesc('created_at')->paginate(5); | |
35 | 122 | |
36 | 123 | if ($request->ajax()) |
37 | 124 | return view('admin.message.index_ajax', compact('Msgs', 'id_admin', 'users')); |
38 | 125 | else |
39 | - return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); | |
126 | + return view('admin.message.index', compact('Msgs', 'id_admin', 'users', 'find_key', 'find_cat')); | |
40 | 127 | } |
41 | 128 | |
42 | 129 | public function messages_sql(Request $request) { |
resources/views/admin/find_message.blade.php
... | ... | @@ -0,0 +1,41 @@ |
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; margin-right:10px"><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: 300px" | |
20 | + type="text" | |
21 | + placeholder="Искать..." | |
22 | + aria-label="Search" | |
23 | + value="{{$find_key}}" | |
24 | + /> | |
25 | + </div> | |
26 | + <div style="float:left; margin-top: -5px;"> | |
27 | + <select | |
28 | + name="category" id="category" | |
29 | + placeholder="Категории" | |
30 | + class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray" | |
31 | + > | |
32 | + <option value="Все категории">Все категории</option> | |
33 | + <option value="Работодатели" @if ($find_cat =="Работодатели") selected @endif>Работодатели</option> | |
34 | + <option value="Соискатели" @if ($find_cat =="Соискатели") selected @endif>Соискатели</option> | |
35 | + <option value="Администраторы" @if ($find_cat =="Администраторы") selected @endif>Администраторы</option> | |
36 | + </select> | |
37 | + </div> | |
38 | + <div style="float: left"> | |
39 | + <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Искать</button> | |
40 | + </div> | |
41 | +</form> |
resources/views/admin/message-read.blade.php
... | ... | @@ -0,0 +1,55 @@ |
1 | +@extends('layout.admin', ['title' => 'Админка - Чтение чужого сообщения']) | |
2 | + | |
3 | +@section('script') | |
4 | +@endsection | |
5 | + | |
6 | +@section('search') | |
7 | +@endsection | |
8 | + | |
9 | +@section('content') | |
10 | +<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800"> | |
11 | + <label class="block text-sm"> | |
12 | + <span class="text-gray-700 dark:text-gray-400">Отправитель</span> | |
13 | + <input name="name1" id="name1" disabled | |
14 | + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input" | |
15 | + placeholder="Название пункта" value="@php echo (isset($message->user_from->name)) ? $message->user_from->name.' ('.$message->user_from->id.')' : 'Не определен'; @endphp" | |
16 | + /> | |
17 | + </label><br> | |
18 | + | |
19 | + <label class="block text-sm"> | |
20 | + <span class="text-gray-700 dark:text-gray-400">Получатель</span> | |
21 | + <input name="name2" id="name2" disabled | |
22 | + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input" | |
23 | + placeholder="Название пункта" value="@php echo (isset($message->user_to->name)) ? $message->user_to->name.' ('.$message->user_to->id.')' : 'Не определен'; @endphp" | |
24 | + /> | |
25 | + </label><br> | |
26 | + | |
27 | + <label class="block text-sm"> | |
28 | + <span class="text-gray-700 dark:text-gray-400">Текст</span> | |
29 | + <textarea name="text" id="text" disabled | |
30 | + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input" | |
31 | + placeholder="Текст">{{ $message->text }}</textarea> | |
32 | + </label><br> | |
33 | + | |
34 | + <label class="block text-sm"> | |
35 | + <span class="text-gray-700 dark:text-gray-400">Дата отправки</span> | |
36 | + <input name="created_at" id="created_at" disabled | |
37 | + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input" | |
38 | + placeholder="Дата отправки" value="{{ $message->created_at }}" | |
39 | + /> | |
40 | + </label><br> | |
41 | + | |
42 | + <label class="block text-sm"> | |
43 | + <span class="text-gray-700 dark:text-gray-400">Дата изменения</span> | |
44 | + <input name="updated_at" id="updated_at" disabled | |
45 | + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input" | |
46 | + placeholder="Дата редактирования" value="{{ $message->updated_at }}" | |
47 | + /> | |
48 | + </label><br> | |
49 | + | |
50 | + <a href="{{ route('admin.messages') }}" | |
51 | + class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple" | |
52 | + style="display: -webkit-inline-box; height: 30px!important;" | |
53 | + >Назад</a> | |
54 | +</div> | |
55 | +@endsection |
resources/views/admin/message/index.blade.php
resources/views/admin/messages.blade.php
... | ... | @@ -4,32 +4,7 @@ |
4 | 4 | @endsection |
5 | 5 | |
6 | 6 | @section('search') |
7 | - <!--<div class="absolute inset-y-0 flex items-center pl-2"> | |
8 | - <svg | |
9 | - class="w-4 h-4" | |
10 | - aria-hidden="true" | |
11 | - fill="currentColor" | |
12 | - viewBox="0 0 20 20" | |
13 | - > | |
14 | - <path | |
15 | - fill-rule="evenodd" | |
16 | - 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" | |
17 | - clip-rule="evenodd" | |
18 | - ></path> | |
19 | - </svg> | |
20 | - </div> | |
21 | - <form action="" method="POST"> | |
22 | - <div style="float:left;"><input | |
23 | - 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" | |
24 | - style="width: 400px" | |
25 | - type="text" | |
26 | - placeholder="Искать компанию или вакансию" | |
27 | - aria-label="Search" | |
28 | - /></div> | |
29 | - <div style="float: left"> | |
30 | - <button type="submit" class="px-3 py-1 rounded-md focus:outline-none focus:shadow-outline-purple">Поиск</button> | |
31 | - </div> | |
32 | - </form>--> | |
7 | + @include('admin.find_message') | |
33 | 8 | @endsection |
34 | 9 | |
35 | 10 | @section('content') |
... | ... | @@ -43,8 +18,8 @@ |
43 | 18 | <th class="px-4 py-3">№</th> |
44 | 19 | <th class="px-4 py-3">От юзера</th> |
45 | 20 | <th class="px-4 py-3">К юзеру</th> |
46 | - <th class="px-4 py-3">Заголовок</th> | |
47 | 21 | <th class="px-4 py-3">Отклик</th> |
22 | + <th class="px-4 py-3">Читать</th> | |
48 | 23 | <th class="px-4 py-3">Дата</th> |
49 | 24 | </tr> |
50 | 25 | </thead> |
... | ... | @@ -69,9 +44,6 @@ |
69 | 44 | @endif |
70 | 45 | </td> |
71 | 46 | <td class="px-4 py-3"> |
72 | - {{$msg->title}} | |
73 | - </td> | |
74 | - <td class="px-4 py-3"> | |
75 | 47 | <div class="flex items-center text-sm"> |
76 | 48 | <div> |
77 | 49 | @if ($msg->response->count()) |
... | ... | @@ -83,6 +55,9 @@ |
83 | 55 | </div> |
84 | 56 | </td> |
85 | 57 | <td class="px-4 py-3 text-sm"> |
58 | + <a style="text-decoration: underline;" href="{{ route('admin.read-message', ['message' => $msg->id]) }}">Читать</a> | |
59 | + </td> | |
60 | + <td class="px-4 py-3 text-sm"> | |
86 | 61 | {{ $msg->created_at }} |
87 | 62 | </td> |
88 | 63 | </tr> |
resources/views/admin/users/profile.blade.php
... | ... | @@ -86,7 +86,6 @@ |
86 | 86 | </label><br> |
87 | 87 | |
88 | 88 | |
89 | - | |
90 | 89 | <div class="flex flex-col flex-wrap mb-4 space-y-4 md:flex-row md:items-end md:space-x-4"> |
91 | 90 | <div> |
92 | 91 | <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple"> |
routes/web.php
... | ... | @@ -213,6 +213,9 @@ Route::group([ |
213 | 213 | |
214 | 214 | // кабинет - сообщения (чтение чужих) |
215 | 215 | Route::get('messages', [MsgAnswersController::class, 'messages'])->name('messages'); |
216 | + // кабинет - просмотр сообщения чужого (чтение) | |
217 | + Route::get('messages/{message}', [MsgAnswersController::class, 'read_message'])->name('read-message'); | |
218 | + | |
216 | 219 | // кабинет - сообщения (админские) |
217 | 220 | Route::get('admin-messages', [MsgAnswersController::class, 'admin_messages'])->name('admin-messages'); |
218 | 221 | // кабинет - сообщения (админские) |