From a89ff088a2ae8caff3d748b0b7aedb481bc78884 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: Mon, 9 Oct 2023 16:00:15 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=D0=BE=D0=B2=D0=B0=D1?= =?UTF-8?q?=8F=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=D1=85=20=D0=B0=D0?= =?UTF-8?q?=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/MsgAnswersController.php | 101 ++++++++++++++++++-- resources/views/admin/find_message.blade.php | 41 ++++++++ resources/views/admin/message-read.blade.php | 55 +++++++++++ resources/views/admin/message/index.blade.php | 2 +- resources/views/admin/messages.blade.php | 35 +------ resources/views/admin/users/profile.blade.php | 1 - routes/web.php | 3 + 7 files changed, 199 insertions(+), 39 deletions(-) create mode 100644 resources/views/admin/find_message.blade.php create mode 100644 resources/views/admin/message-read.blade.php diff --git a/app/Http/Controllers/Admin/MsgAnswersController.php b/app/Http/Controllers/Admin/MsgAnswersController.php index 18350ad..d4d8218 100644 --- a/app/Http/Controllers/Admin/MsgAnswersController.php +++ b/app/Http/Controllers/Admin/MsgAnswersController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Message; use App\Models\User; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -12,10 +13,88 @@ use Illuminate\Support\Facades\Validator; class MsgAnswersController extends Controller { - public function messages() { - $Msgs = Message::with('user_from')->with('user_to')->with('response')->orderByDesc('created_at')->paginate(25); + public function messages(Request $request) { + $find_key = ""; + $find_cat = ""; + $Msgs = Message::with('user_from')->with('user_to')->with('response'); + + $Msgs = $this->filter($Msgs, $request, $find_key, $find_cat); + + $Msgs = $Msgs->orderByDesc('created_at')->paginate(25); + + return view('admin.messages', compact('Msgs', 'find_key', 'find_cat')); + } + + public function read_message(Message $message) { + return view('admin.message-read', compact('message')); + } + + public function filter($Msgs, Request $request, &$find_key, &$find_cat) { + if (isset($request->find)) { + $find_key = $request->find; + $Msgs = $Msgs->where(function($q) use ($find_key) { + $q->whereHas('user_from', + function (Builder $query) use ($find_key) { + $query->where('name', 'LIKE', "%$find_key%"); + } + )-> + orWhereHas('user_to', + function (Builder $query) use ($find_key) { + $query->where('name', 'LIKE', "%$find_key%"); + } + ); + }); + } + + if (isset($request->category)) { + $find_cat = $request->category; + + switch ($find_cat) { + case 'Работодатели': + $Msgs = $Msgs->where(function($q) { + $q->whereHas('user_to', + function (Builder $query) { + $query->where('is_worker', '0'); + } + )->orwhereHas('user_from', + function (Builder $query) { + $query->where('is_worker', '0'); + } + ); + }); + break; + case 'Соискатели': + $Msgs = $Msgs->where(function($q) { + $q->whereHas('user_to', + function (Builder $query) { + $query->where('is_worker', '1'); + } + )->orwhereHas('user_from', + function (Builder $query) { + $query->where('is_worker', '1'); + } + ); + }); + break; + case 'Администраторы': + $Msgs = $Msgs->where(function($q) { + $q->whereHas('user_to', + function (Builder $query) { + $query->where('admin', '1'); + } + )->orwhereHas('user_from', + function (Builder $query) { + $query->where('admin', '1'); + } + ); + }); + break; + default:break; + } + } + + return $Msgs; - return view('admin.messages', compact('Msgs')); } public function admin_messages(Request $request) { @@ -29,14 +108,22 @@ class MsgAnswersController extends Controller $users = User::query()->OrderBy('name')->get(); $Msgs = Message::with('user_from')->with('user_to')->with('response') - ->where('user_id', '=', $id_admin) - ->orWhere('to_user_id', '=', $id_admin) - ->orderByDesc('created_at')->paginate(5); + ->where(function($query) use ($id_admin) { + $query->where('user_id', '=', $id_admin) + ->orWhere('to_user_id', '=', $id_admin); + }); + + $find_key = ''; + $find_cat = ''; + + $Msgs = $this->filter($Msgs, $request, $find_key, $find_cat); + + $Msgs = $Msgs->orderByDesc('created_at')->paginate(5); 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')); + return view('admin.message.index', compact('Msgs', 'id_admin', 'users', 'find_key', 'find_cat')); } public function messages_sql(Request $request) { diff --git a/resources/views/admin/find_message.blade.php b/resources/views/admin/find_message.blade.php new file mode 100644 index 0000000..eaca810 --- /dev/null +++ b/resources/views/admin/find_message.blade.php @@ -0,0 +1,41 @@ +
+ +
+
+
+
+
+ +
+
+ +
+
diff --git a/resources/views/admin/message-read.blade.php b/resources/views/admin/message-read.blade.php new file mode 100644 index 0000000..7bba7fe --- /dev/null +++ b/resources/views/admin/message-read.blade.php @@ -0,0 +1,55 @@ +@extends('layout.admin', ['title' => 'Админка - Чтение чужого сообщения']) + +@section('script') +@endsection + +@section('search') +@endsection + +@section('content') +
+
+ +
+ +
+ +
+ +
+ + Назад +
+@endsection diff --git a/resources/views/admin/message/index.blade.php b/resources/views/admin/message/index.blade.php index ac65e53..5af7dfb 100644 --- a/resources/views/admin/message/index.blade.php +++ b/resources/views/admin/message/index.blade.php @@ -39,7 +39,7 @@ @endsection @section('search') - + @include('admin.find_message') @endsection @section('content') diff --git a/resources/views/admin/messages.blade.php b/resources/views/admin/messages.blade.php index ddca914..4a9a1ca 100644 --- a/resources/views/admin/messages.blade.php +++ b/resources/views/admin/messages.blade.php @@ -4,32 +4,7 @@ @endsection @section('search') - + @include('admin.find_message') @endsection @section('content') @@ -43,8 +18,8 @@ № От юзера К юзеру - Заголовок Отклик + Читать Дата @@ -69,9 +44,6 @@ @endif - {{$msg->title}} - -
@if ($msg->response->count()) @@ -83,6 +55,9 @@
+ Читать + + {{ $msg->created_at }} diff --git a/resources/views/admin/users/profile.blade.php b/resources/views/admin/users/profile.blade.php index 7371c31..4cae344 100644 --- a/resources/views/admin/users/profile.blade.php +++ b/resources/views/admin/users/profile.blade.php @@ -86,7 +86,6 @@
-