Commit f060aa75b26e4219843abdd286118db933005718
1 parent
93a3f79f0c
Exists in
master
and in
1 other branch
Счетчик сообщений, метки непрочитанных сообщений администратора
Showing 6 changed files with 137 additions and 33 deletions Side-by-side Diff
app/Http/Controllers/Admin/AdminController.php
... | ... | @@ -155,13 +155,21 @@ class AdminController extends Controller |
155 | 155 | $request->offsetUnset('id'); |
156 | 156 | $user->update($request->all()); |
157 | 157 | } |
158 | - | |
159 | - $users = User::where('admin', '1')->paginate(15); | |
158 | + $find_key = ''; | |
159 | + $users = User::where('admin', '1'); | |
160 | + if (isset($request->find)) { | |
161 | + $find_key = $request->find; | |
162 | + $users = $users->where(function($query) use($find_key) { | |
163 | + $query->Where('name', 'LIKE', "%$find_key%") | |
164 | + ->orWhere('email', 'LIKE', "%$find_key%"); | |
165 | + }); | |
166 | + } | |
167 | + $users = $users->paginate(15); | |
160 | 168 | |
161 | 169 | if ($request->ajax()) { |
162 | 170 | return view('admin.users.index_ajax', compact('users', 'id_admin')); |
163 | 171 | } else { |
164 | - return view('admin.users.index', compact('users', 'title', 'id_admin')); | |
172 | + return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key')); | |
165 | 173 | } |
166 | 174 | } |
167 | 175 |
app/Http/Controllers/Admin/MsgAnswersController.php
... | ... | @@ -19,6 +19,12 @@ class MsgAnswersController extends Controller |
19 | 19 | } |
20 | 20 | |
21 | 21 | public function admin_messages(Request $request) { |
22 | + if ($request->ajax()) { | |
23 | + $msg = Message::find($request->id); | |
24 | + $msg->flag_new = !($request->flag_new); | |
25 | + $msg->save(); | |
26 | + } | |
27 | + | |
22 | 28 | $id_admin = Auth::user()->id; |
23 | 29 | $users = User::query()->OrderBy('name')->get(); |
24 | 30 | |
... | ... | @@ -26,7 +32,10 @@ class MsgAnswersController extends Controller |
26 | 32 | ->orWhere('to_user_id', '=', $id_admin) |
27 | 33 | ->orderByDesc('created_at')->paginate(5); |
28 | 34 | |
29 | - return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); | |
35 | + if ($request->ajax()) | |
36 | + return view('admin.message.index_ajax', compact('Msgs', 'id_admin', 'users')); | |
37 | + else | |
38 | + return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); | |
30 | 39 | } |
31 | 40 | |
32 | 41 | public function messages_sql(Request $request) { |
app/Providers/MyServiceProvider.php
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | namespace App\Providers; |
4 | 4 | |
5 | 5 | use App\Models\Job_title; |
6 | +use Illuminate\Support\Facades\Auth; | |
7 | +use Illuminate\Support\Facades\DB; | |
6 | 8 | use Illuminate\Support\Facades\View; |
7 | 9 | use Illuminate\Support\ServiceProvider; |
8 | 10 | |
... | ... | @@ -45,5 +47,20 @@ class MyServiceProvider extends ServiceProvider |
45 | 47 | |
46 | 48 | } |
47 | 49 | ); |
50 | + | |
51 | + $views2 = ['layout.admin']; | |
52 | + | |
53 | + View::composer($views2, | |
54 | + function($view){ | |
55 | + $id = Auth::user()->id; | |
56 | + $query = DB::select(DB::raw('SELECT count(*) as MsgCount | |
57 | + FROM messages m1 | |
58 | + Where ((m1.flag_new = 1) and (m1.to_user_id = :uid)) | |
59 | + '), ['uid' => $id] | |
60 | + ); | |
61 | + | |
62 | + $view->with(['MsgCount' => $query[0]->MsgCount]); | |
63 | + } | |
64 | + ); | |
48 | 65 | } |
49 | 66 | } |
resources/views/admin/message/index.blade.php
1 | 1 | @extends('layout.admin', ['title' => 'Админка - Сообщения адмистратора']) |
2 | 2 | |
3 | 3 | @section('script') |
4 | + <script> | |
5 | + $(document).ready(function() { | |
6 | + $(document).on('change', '.checkread', function () { | |
7 | + var this_ = $(this); | |
8 | + var value = this_.val(); | |
9 | + var ajax_block = $('#ajax_block'); | |
10 | + var bool = 0; | |
11 | + | |
12 | + if(this.checked){ | |
13 | + bool = 1; | |
14 | + } else { | |
15 | + bool = 0; | |
16 | + } | |
17 | + | |
18 | + $.ajax({ | |
19 | + type: "GET", | |
20 | + url: "{{ url()->full()}}", | |
21 | + data: "id=" + value + "&flag_new=" + bool, | |
22 | + success: function (data) { | |
23 | + console.log('Обновление таблицы сообщений администратора '); | |
24 | + //data = JSON.parse(data); | |
25 | + //console.log(data); | |
26 | + ajax_block.html(data); | |
27 | + }, | |
28 | + headers: { | |
29 | + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
30 | + }, | |
31 | + error: function (data) { | |
32 | + console.log('Error: ' + data); | |
33 | + } | |
34 | + }); | |
35 | + }); | |
36 | + | |
37 | + }); | |
38 | + </script> | |
4 | 39 | @endsection |
5 | 40 | |
6 | 41 | @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>--> | |
42 | + | |
33 | 43 | @endsection |
34 | 44 | |
35 | 45 | @section('content') |
... | ... | @@ -45,11 +55,13 @@ |
45 | 55 | <th class="px-4 py-3">К юзеру</th> |
46 | 56 | <th class="px-4 py-3">Текст</th> |
47 | 57 | <th class="px-4 py-3">Дата</th> |
58 | + <th class="px-4 py-3">Прочтено</th> | |
48 | 59 | </tr> |
49 | 60 | </thead> |
50 | 61 | <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"> |
51 | 62 | @foreach($Msgs as $msg) |
52 | - <tr class="text-gray-700 dark:text-gray-400"> | |
63 | + <tr class="text-gray-700 dark:text-gray-400" | |
64 | + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif> | |
53 | 65 | <td class="px-4 py-3"> |
54 | 66 | {{$msg->id}} |
55 | 67 | </td> |
... | ... | @@ -68,6 +80,11 @@ |
68 | 80 | <td class="px-4 py-3 text-sm"> |
69 | 81 | {{ $msg->created_at }} |
70 | 82 | </td> |
83 | + <td class="px-4 py-3 text-sm"> | |
84 | + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) | |
85 | + <input type="checkbox" class="checkread" value="{{$msg->id}}" name="read_{{$msg->id}}"/> | |
86 | + @endif | |
87 | + </td> | |
71 | 88 | </tr> |
72 | 89 | @endforeach |
73 | 90 | </tbody> |
resources/views/admin/message/index_ajax.blade.php
... | ... | @@ -0,0 +1,50 @@ |
1 | +<div class="w-full overflow-x-auto"> | |
2 | + <table class="w-full whitespace-no-wrap"> | |
3 | + <thead> | |
4 | + <tr | |
5 | + class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800" | |
6 | + > | |
7 | + <th class="px-4 py-3">№</th> | |
8 | + <th class="px-4 py-3">От юзера</th> | |
9 | + <th class="px-4 py-3">К юзеру</th> | |
10 | + <th class="px-4 py-3">Текст</th> | |
11 | + <th class="px-4 py-3">Дата</th> | |
12 | + <th class="px-4 py-3">Прочтено</th> | |
13 | + </tr> | |
14 | + </thead> | |
15 | + <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"> | |
16 | + @foreach($Msgs as $msg) | |
17 | + <tr class="text-gray-700 dark:text-gray-400" | |
18 | + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif> | |
19 | + <td class="px-4 py-3"> | |
20 | + {{$msg->id}} | |
21 | + </td> | |
22 | + <td class="px-4 py-3"> | |
23 | + {{$msg->user_from->name}} ({{$msg->user_from->id}}) | |
24 | + </td> | |
25 | + <td class="px-4 py-3"> | |
26 | + {{$msg->user_to->name}} ({{$msg->user_to->id}}) | |
27 | + </td> | |
28 | + <td class="px-4 py-3"> | |
29 | + {{$msg->title}} | |
30 | + <div class="flex items-center text-sm"> | |
31 | + <textarea cols="7" style="width:250px;">{{ $msg->text }}</textarea> | |
32 | + </div> | |
33 | + </td> | |
34 | + <td class="px-4 py-3 text-sm"> | |
35 | + {{ $msg->created_at }} | |
36 | + </td> | |
37 | + <td class="px-4 py-3 text-sm"> | |
38 | + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) | |
39 | + <input type="checkbox" class="checkread" value="{{$msg->id}}" name="read_{{$msg->id}}"/> | |
40 | + @endif | |
41 | + </td> | |
42 | + </tr> | |
43 | + @endforeach | |
44 | + </tbody> | |
45 | + </table> | |
46 | +</div> | |
47 | + | |
48 | +<div class="grid px-4 py-3 text-xs font-semibold tracking-wide text-gray-500 uppercase border-t dark:border-gray-700 bg-gray-50 sm:grid-cols-9 dark:text-gray-400 dark:bg-gray-800"> | |
49 | + <?=$Msgs->appends($_GET)->links('admin.pagginate'); ?> | |
50 | +</div> |
resources/views/layout/admin.blade.php
... | ... | @@ -900,11 +900,14 @@ |
900 | 900 | href="{{ route('admin.admin-messages') }}" |
901 | 901 | > |
902 | 902 | <span>Сообщения</span> |
903 | + @if($MsgCount > 0) | |
903 | 904 | <span |
904 | 905 | class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-red-600 bg-red-100 rounded-full dark:text-red-100 dark:bg-red-600" |
905 | 906 | > |
906 | - 13 | |
907 | - </span> | |
907 | + | |
908 | + {{ $MsgCount }} | |
909 | + </span> | |
910 | + @endif | |
908 | 911 | </a> |
909 | 912 | </li> |
910 | 913 | <!--<li class="flex"> |