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 @@
-