From f060aa75b26e4219843abdd286118db933005718 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: Wed, 20 Sep 2023 18:16:00 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=87=D0=B5=D1=82=D1=87=D0=B8=D0=BA=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9,=20=D0=BC=D0=B5=D1?= =?UTF-8?q?=82=D0=BA=D0=B8=20=D0=BD=D0=B5=D0=BF=D1=80=D0=BE=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0?= =?UTF-8?q?=B5=D0=BD=D0=B8=D0=B9=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/AdminController.php | 14 +++- .../Controllers/Admin/MsgAnswersController.php | 11 ++- app/Providers/MyServiceProvider.php | 17 +++++ resources/views/admin/message/index.blade.php | 71 ++++++++++++-------- resources/views/admin/message/index_ajax.blade.php | 50 ++++++++++++++ resources/views/layout/admin.blade.php | 7 +- 6 files changed, 137 insertions(+), 33 deletions(-) create mode 100644 resources/views/admin/message/index_ajax.blade.php diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index e184976..29868cc 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -155,13 +155,21 @@ class AdminController extends Controller $request->offsetUnset('id'); $user->update($request->all()); } - - $users = User::where('admin', '1')->paginate(15); + $find_key = ''; + $users = User::where('admin', '1'); + 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%"); + }); + } + $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/MsgAnswersController.php b/app/Http/Controllers/Admin/MsgAnswersController.php index cf60f60..d2029b5 100644 --- a/app/Http/Controllers/Admin/MsgAnswersController.php +++ b/app/Http/Controllers/Admin/MsgAnswersController.php @@ -19,6 +19,12 @@ class MsgAnswersController extends Controller } public function admin_messages(Request $request) { + if ($request->ajax()) { + $msg = Message::find($request->id); + $msg->flag_new = !($request->flag_new); + $msg->save(); + } + $id_admin = Auth::user()->id; $users = User::query()->OrderBy('name')->get(); @@ -26,7 +32,10 @@ class MsgAnswersController extends Controller ->orWhere('to_user_id', '=', $id_admin) ->orderByDesc('created_at')->paginate(5); - return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); + if ($request->ajax()) + return view('admin.message.index_ajax', compact('Msgs', 'id_admin', 'users')); + else + return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); } public function messages_sql(Request $request) { diff --git a/app/Providers/MyServiceProvider.php b/app/Providers/MyServiceProvider.php index f3c2dde..d7b8908 100644 --- a/app/Providers/MyServiceProvider.php +++ b/app/Providers/MyServiceProvider.php @@ -3,6 +3,8 @@ namespace App\Providers; use App\Models\Job_title; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -45,5 +47,20 @@ class MyServiceProvider extends ServiceProvider } ); + + $views2 = ['layout.admin']; + + View::composer($views2, + function($view){ + $id = Auth::user()->id; + $query = DB::select(DB::raw('SELECT count(*) as MsgCount + FROM messages m1 + Where ((m1.flag_new = 1) and (m1.to_user_id = :uid)) + '), ['uid' => $id] + ); + + $view->with(['MsgCount' => $query[0]->MsgCount]); + } + ); } } diff --git a/resources/views/admin/message/index.blade.php b/resources/views/admin/message/index.blade.php index be88552..d33ee67 100644 --- a/resources/views/admin/message/index.blade.php +++ b/resources/views/admin/message/index.blade.php @@ -1,35 +1,45 @@ @extends('layout.admin', ['title' => 'Админка - Сообщения адмистратора']) @section('script') + @endsection @section('search') - + @endsection @section('content') @@ -45,11 +55,13 @@ К юзеру Текст Дата + Прочтено @foreach($Msgs as $msg) - + user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif> {{$msg->id}} @@ -68,6 +80,11 @@ {{ $msg->created_at }} + + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) + + @endif + @endforeach diff --git a/resources/views/admin/message/index_ajax.blade.php b/resources/views/admin/message/index_ajax.blade.php new file mode 100644 index 0000000..c2a974e --- /dev/null +++ b/resources/views/admin/message/index_ajax.blade.php @@ -0,0 +1,50 @@ +
+ + + + + + + + + + + + + @foreach($Msgs as $msg) + user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif> + + + + + + + + @endforeach + +
От юзераК юзеруТекстДатаПрочтено
+ {{$msg->id}} + + {{$msg->user_from->name}} ({{$msg->user_from->id}}) + + {{$msg->user_to->name}} ({{$msg->user_to->id}}) + + {{$msg->title}} +
+ +
+
+ {{ $msg->created_at }} + + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) + + @endif +
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> +
diff --git a/resources/views/layout/admin.blade.php b/resources/views/layout/admin.blade.php index 21cd48e..949b614 100644 --- a/resources/views/layout/admin.blade.php +++ b/resources/views/layout/admin.blade.php @@ -900,11 +900,14 @@ href="{{ route('admin.admin-messages') }}" > Сообщения + @if($MsgCount > 0) - 13 - + + {{ $MsgCount }} + + @endif