Commit f98ccb92caa998d4b50bd3ef07af55db88f5ab10

Authored by Сергей П
1 parent d2571da21e
Exists in master

Массова рассылка

Showing 15 changed files with 381 additions and 91 deletions Side-by-side Diff

app/Http/Controllers/EmployerController.php
... ... @@ -342,12 +342,13 @@ class EmployerController extends Controller
342 342  
343 343 $chats = Chat::get_user_chats($user_id);
344 344 $user_type = 'employer';
  345 + $admin_chat = false;
345 346  
346   - return view('employers.messages', compact('chats','user_id', 'user_type'));
  347 + return view('employers.messages', compact('chats', 'admin_chat', 'user_id', 'user_type'));
347 348 }
348 349  
349 350 // Диалог между пользователями
350   - public function dialog(Request $request, User_Model $user1, User_Model $user2) {
  351 + public function dialog(Chat $chat, Request $request) {
351 352 // Получение параметров.
352 353 if ($request->has('ad_employer')){
353 354 $ad_employer = $request->get('ad_employer');
... ... @@ -355,29 +356,12 @@ class EmployerController extends Controller
355 356 $ad_employer = 0;
356 357 }
357 358  
358   - if (isset($user2->id)) {
359   - $companion = User_Model::query()->with('workers')->
360   - with('employers')->
361   - where('id', $user2->id)->first();
362   - }
  359 + $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
  360 + $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
363 361  
364   - $Messages = Message::query()
365   - ->where(function($query) use ($user1, $user2) {
366   - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
367   - })
368   - ->orWhere(function($query) use ($user1, $user2) {
369   - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
370   - })
371   - ->orderBy('created_at')
372   - ->get()
373   - ;
  362 + $Messages = Chat::get_chat_messages($chat);
374 363  
375   - $sender = $user1;
376   -
377   - Message::where('user_id', '=', $user2->id)
378   - ->where('to_user_id', '=', $user1->id)
379   - ->update(['flag_new' => 0])
380   - ;
  364 + Message::where('user_id', '=', $chat->to_user_id)->where('to_user_id', '=', $chat->user_id)->update(['flag_new' => 0]);
381 365  
382 366 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages'));
383 367 }
app/Http/Controllers/HomeController.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace App\Http\Controllers;
4 4  
  5 +use App\Models\Message;
5 6 use Illuminate\Http\Request;
6 7  
7 8 class HomeController extends Controller
... ... @@ -25,4 +26,28 @@ class HomeController extends Controller
25 26 {
26 27 return view('home');
27 28 }
  29 +
  30 + public function send_message(Request $request)
  31 + {
  32 + $user_id = Auth()->user()->id;
  33 +
  34 + $message_params = [
  35 + 'text' => $request->input('text'),
  36 + 'reply_message_id' => $request->input('reply_message_id', null),
  37 + ];
  38 +
  39 + $new_message = Message::add_message(
  40 + $request,
  41 + $user_id,
  42 + $request->input('to_user_id'),
  43 + $message_params
  44 + );
  45 +
  46 + $user_type = Auth()->user()->is_worker ? 'worker' : 'employer';
  47 +
  48 + return response()->json([
  49 + 'success' => true,
  50 + 'url_redirect' => route($user_type . '.dialog', ['chat' => $new_message->chat_id_to])
  51 + ]);
  52 + }
28 53 }
app/Http/Controllers/WorkerController.php
... ... @@ -496,9 +496,10 @@ class WorkerController extends Controller
496 496 $user_id = Auth()->user()->id;
497 497  
498 498 $chats = Chat::get_user_chats($user_id);
  499 + $admin_chat = Chat::get_user_admin_chat($user_id);
499 500 $user_type = 'worker';
500 501  
501   - return view('workers.messages', compact('chats','user_id', 'user_type'));
  502 + return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type'));
502 503 }
503 504  
504 505 // Избранный
... ... @@ -803,7 +804,7 @@ class WorkerController extends Controller
803 804 }
804 805  
805 806 //Переписка
806   - public function dialog(User_Model $user1, User_Model $user2, Request $request) {
  807 + public function dialog(Chat $chat, Request $request) {
807 808 // Получение параметров.
808 809 if ($request->has('ad_employer')){
809 810 $ad_employer = $request->get('ad_employer');
... ... @@ -811,35 +812,16 @@ class WorkerController extends Controller
811 812 $ad_employer = 0;
812 813 }
813 814  
814   - if (isset($user1->id)) {
815   - $sender = User_Model::query()->with('workers')->
816   - with('employers')->
817   - where('id', $user1->id)->first();
818   - }
  815 + $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
  816 + $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
819 817  
820   - if (isset($user2->id)) {
821   - $companion = User_Model::query()
822   - ->with('workers')
823   - ->with('employers')
824   - ->where('id', $user2->id)
825   - ->first()
826   - ;
827   - }
828   -
829   - $Messages = Message::query()->
830   - where(function($query) use ($user1, $user2) {
831   - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
832   - })->orWhere(function($query) use ($user1, $user2) {
833   - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
834   - })->OrderBy('created_at')
835   - ->get()
836   - ;
  818 + $Messages = Chat::get_chat_messages($chat);
837 819  
838   - Message::where('user_id', '=', $user2->id)
839   - ->where('to_user_id', '=', $user1->id)
  820 + Message::where('user_id', '=', $chat->to_user_id)
  821 + ->where('to_user_id', '=', $chat->user_id)
840 822 ->update(['flag_new' => 0]);
841 823  
842   - return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer'));
  824 + return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer'));
843 825 }
844 826  
845 827 // Даунылоады
... ... @@ -1078,10 +1060,10 @@ class WorkerController extends Controller
1078 1060 return redirect()->route('worker.dialog', ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name])
1079 1061 ->withErrors($validator);
1080 1062 } else {
1081   - Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
  1063 + $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
1082 1064  
1083 1065 return redirect()->route('worker.dialog',
1084   - ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
  1066 + ['user1' => $user1, 'user2' => $user2, 'chat' => $new_message->chat_id_from]);
1085 1067  
1086 1068 }
1087 1069 }
... ... @@ -17,7 +17,8 @@ class Chat extends Model
17 17 'is_fixed',
18 18 'last_message_date',
19 19 'last_message_id',
20   - 'fixed_time'
  20 + 'fixed_time',
  21 + 'is_admin_chat'
21 22 ];
22 23  
23 24 public function user() {
... ... @@ -74,4 +75,46 @@ class Chat extends Model
74 75 ;
75 76 }
76 77  
  78 + public static function get_user_admin_chat(int $user_id)
  79 + {
  80 + return Chat::query()
  81 + ->with('last_message')
  82 + ->withCount(['unread_messages' => function ($query) use($user_id) {
  83 + $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
  84 + }])
  85 + ->where('to_user_id', '=', $user_id)
  86 + ->where('is_admin_chat', 1)
  87 + ->first()
  88 + ;
  89 + }
  90 +
  91 + public static function get_chat_messages(Chat $chat){
  92 + if ($chat->is_admin_chat){
  93 + return Message::query()
  94 + ->where('chat_id_to', $chat->id)
  95 + ->where('to_user_id', $chat->to_user_id)
  96 + ->orderBy('created_at')
  97 + ->get()
  98 + ;
  99 + } else {
  100 + return Message::query()
  101 + ->where(function ($query) use ($chat) {
  102 + $query->where('chat_id_from', $chat->id)->orWhere('chat_id_to', $chat->id);
  103 + })
  104 + ->where(function($query) use ($chat) {
  105 + $query
  106 + ->where(function($query) use ($chat) {
  107 + $query->where('user_id', $chat->user_id)->where('to_user_id', $chat->to_user_id);
  108 + })
  109 + ->orWhere(function($query) use ($chat) {
  110 + $query->where('user_id', $chat->to_user_id)->where('to_user_id', $chat->user_id);
  111 + })
  112 + ;
  113 + })
  114 + ->OrderBy('created_at')
  115 + ->get()
  116 + ;
  117 + }
  118 + }
  119 +
77 120 }
app/Models/Message.php
... ... @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
6 6 use Illuminate\Database\Eloquent\Model;
7 7 use Illuminate\Http\Request;
8 8 use Illuminate\Support\Facades\Validator;
  9 +use mysql_xdevapi\Collection;
9 10  
10 11 class Message extends Model
11 12 {
... ... @@ -19,7 +20,10 @@ class Message extends Model
19 20 'file',
20 21 'flag_new',
21 22 'ad_employer_id',
22   - 'job_title_id'
  23 + 'job_title_id',
  24 + 'chat_id_from',
  25 + 'chat_id_to',
  26 + 'reply_message_id',
23 27 ];
24 28  
25 29  
... ... @@ -43,34 +47,57 @@ class Message extends Model
43 47 }
44 48  
45 49 public static function add_message(
46   - Request $request,
  50 + ?Request $request,
47 51 int $user_id,
48 52 int $to_user_id,
49 53 array $message_params,
50   - string $file_store_path = '/'
  54 + string $file_store_path = '/',
  55 + bool $is_admin_chat = false
51 56 ) {
52 57 $message_params['user_id'] = $user_id;
53 58 $message_params['to_user_id'] = $to_user_id;
54   - if ($request->has('file')) {
  59 + if ($request && $request->has('file')) {
55 60 $message_params['file'] = $request->file('file')->store($file_store_path, 'public');
56 61 }
57 62  
  63 + $chat_form = Chat::firstOrCreate([
  64 + 'user_id' => $is_admin_chat ? 0 : $user_id,
  65 + 'to_user_id' => $to_user_id,
  66 + 'is_removed' => 0,
  67 + 'is_admin_chat' => $is_admin_chat ? 1 : 0,
  68 + ]);
  69 + $message_params[$is_admin_chat ? 'chat_id_to' : 'chat_id_from'] = $chat_form->id;
  70 +
  71 + if (!$is_admin_chat) {
  72 + $chat_to = Chat::firstOrCreate([
  73 + 'user_id' => $to_user_id,
  74 + 'to_user_id' => $user_id,
  75 + 'is_removed' => 0
  76 + ]);
  77 + $message_params['chat_id_to'] = $chat_to->id;
  78 + }
  79 +
58 80 $new_message = Message::create($message_params);
59 81  
60 82 if (!empty($new_message->id)) {
61   - Chat::updateOrCreate(
62   - ['user_id' => $user_id, 'to_user_id' => $to_user_id],
63   - ['user_id' => $user_id, 'to_user_id' => $to_user_id, 'last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]
64   - );
65   -
66   - Chat::updateOrCreate(
67   - ['user_id' => $to_user_id, 'to_user_id' => $user_id],
68   - ['user_id' => $to_user_id, 'to_user_id' => $user_id, 'last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]
69   - );
  83 + $chat_form->update(['last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]);
  84 +
  85 + if (!$is_admin_chat) {
  86 + $chat_to->update(['last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]);
  87 + }
70 88 }
71 89  
72   - return $new_message->id ?? 0;
  90 + return $new_message ?? false;
  91 + }
  92 +
  93 + public function getReplyMessageAttribute()
  94 + {
  95 + $reply_message = false;
  96 + if ($this->attributes['reply_message_id']){
  97 + $reply_message = self::find($this->attributes['reply_message_id']);
  98 + }
73 99  
  100 + return $reply_message;
74 101 }
75 102  
76 103 }
app/Models/MessagesRequests.php
... ... @@ -30,6 +30,25 @@ class MessagesRequests extends Model
30 30 public static function send_message($message_request_id)
31 31 {
32 32 $message_request = MessagesRequests::find($message_request_id);
  33 + $job_ids = json_decode($message_request->job_titles);
  34 +
  35 + if (!empty($job_ids)){
  36 + $workers = Title_worker::select('worker_id')
  37 + ->whereIN('job_title_id', $job_ids)
  38 + ->groupBy('worker_id')
  39 + ->get()
  40 + ;
  41 +
  42 + if ($workers->count()){
  43 + $message_params = [
  44 + 'text' => $message_request->text
  45 + ];
  46 + foreach ($workers as $worker){
  47 + Message::add_message(null, $message_request->user_id, $worker->worker_id, $message_params, file_store_path : '/', is_admin_chat: true);
  48 + }
  49 + }
  50 + }
  51 +
33 52 $message_request->update(['is_sent' => now()]);
34 53  
35 54 return true;
database/migrations/2024_08_09_071214_alter_table_messages.php
... ... @@ -0,0 +1,36 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::table('messages', function (Blueprint $table) {
  17 + $table->integer('chat_id_from')->nullable(true)->after('to_user_id');
  18 + $table->integer('chat_id_to')->nullable(true)->after('chat_id_from');
  19 + $table->integer('reply_message_id')->nullable(true);
  20 + });
  21 + }
  22 +
  23 + /**
  24 + * Reverse the migrations.
  25 + *
  26 + * @return void
  27 + */
  28 + public function down()
  29 + {
  30 + Schema::table('messages', function (Blueprint $table) {
  31 + $table->dropColumn('chat_id_from');
  32 + $table->dropColumn('chat_id_to');
  33 + $table->dropColumn('reply_message_id');
  34 + });
  35 + }
  36 +};
database/migrations/2024_08_09_072423_alter_table_chats.php
... ... @@ -0,0 +1,34 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::table('chats', function (Blueprint $table) {
  17 + $table->dateTime('last_message_date')->nullable(true)->change();
  18 + $table->integer('last_message_id')->nullable(true)->change();
  19 + $table->boolean('is_admin_chat')->default(false)->after('is_fixed');
  20 + });
  21 + }
  22 +
  23 + /**
  24 + * Reverse the migrations.
  25 + *
  26 + * @return void
  27 + */
  28 + public function down()
  29 + {
  30 + Schema::table('chats', function (Blueprint $table) {
  31 + $table->dropColumn('is_admin_chat');
  32 + });
  33 + }
  34 +};
public/css/style_may2024.css
... ... @@ -7214,6 +7214,19 @@ main + .news {
7214 7214 padding: 10px;
7215 7215 line-height: 1.6;
7216 7216 }
  7217 +.chatbox__item-text .admin-chat-answer{
  7218 + padding: 2px 5px;
  7219 + height: auto;
  7220 + float: right;
  7221 + margin-left: 10px;
  7222 +}
  7223 +.chatbox__item-text .reply-message{
  7224 + border-left: 1px grey solid;
  7225 + padding-left: 11px;
  7226 + font-size: 12px;
  7227 + font-style: italic;
  7228 + margin-top: 10px;
  7229 +}
7217 7230 .chatbox__item-time {
7218 7231 width: 100%;
7219 7232 padding-left: 54px;
resources/views/chats/chats_list.blade.php
1 1 @if ($chats->count())
2 2 @csrf
  3 +
  4 + @if($admin_chat)
  5 + <div class="messages__item hover-shadow admin-chat-wrap">
  6 + <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $admin_chat->id]) }}">
  7 + @include('svg.logo_icon')
  8 + <div class="messages__item-text">
  9 + <div>
  10 + <b>Администратор сайта</b>
  11 + </div>
  12 + <div>
  13 + {{ $admin_chat->last_message->text }}
  14 + </div>
  15 + </div>
  16 + </a>
  17 +
  18 + <div class="messages__item-actions" data-chat-id="{{ $admin_chat->id }}">
  19 + <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($admin_chat->created_at)) }}</div>
  20 + </div>
  21 + </div>
  22 + @endif
  23 +
3 24 @foreach($chats as $chat)
4 25 <div class="messages__item hover-shadow {{ intval($chat->is_fixed) == 1 ? 'chat-fixed' : '' }}">
5   - <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['user1' => $chat->user_id, 'user2' => $chat->to_user_id, 'ad_employer' => 0]) }}">
  26 + <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $chat->id]) }}">
6 27 <div class="messages__item-photo">
7 28 @if (isset($chat->employer->logo))
8 29 <img src="{{ asset(Storage::url($chat->employer->logo)) }}" alt="">
resources/views/employers/dialog.blade.php
... ... @@ -163,7 +163,14 @@
163 163  
164 164 </div>
165 165 <div class="chatbox__item-body">
166   - <div class="chatbox__item-text">{{ $it->text }}</div>
  166 + <div class="chatbox__item-text">
  167 + {{ $it->text }}
  168 + @if($it->reply_message_id)
  169 + <div class="reply-message">
  170 + {{ $it->reply_message->text }}
  171 + </div>
  172 + @endif
  173 + </div>
167 174 </div>
168 175 <div class="chatbox__item-time">{{ $it->created_at }}</div>
169 176 </div>
resources/views/modals/chats/answer_from_admin_chat.blade.php
... ... @@ -0,0 +1,54 @@
  1 +<div class="hide">
  2 + <div id="answer_from_admin_chat_modal" class="modal-dialog">
  3 + <div class="modal-dialog-title">
  4 + <h2>Ответить работодателю</h2>
  5 + </div>
  6 + <div class="modal-dialog-body">
  7 + <textarea class="textarea" name="text" placeholder="" required></textarea>
  8 + </div>
  9 + <div class="modal-dialog-footer">
  10 + <button type="button" class="button answer-from-admin-chat-button">Отправить</button>
  11 + <button type="button" class="button button_light" onclick="$.fancybox.close();">Закрыть</button>
  12 + </div>
  13 + </div>
  14 +</div>
  15 +
  16 +<script>
  17 + $(function (){
  18 + $('.answer-from-admin-chat-button').click(function(){
  19 + spinStart($(this));
  20 + var wrap = $(this).closest('#answer_from_admin_chat_modal');
  21 + var to_user_id = wrap.data('to-user-id');
  22 + var reply_message_id = wrap.data('message-id');
  23 + var textarea = wrap.find('[name="text"]');
  24 + var text = textarea.val()
  25 +
  26 + textarea.removeClass('border-red');
  27 + if (!text.trim()){
  28 + textarea.addClass('border-red');
  29 + return;
  30 + }
  31 +
  32 + $.ajax({
  33 + type: "POST",
  34 + url: "{{ route('send_message') }}",
  35 + data: {
  36 + to_user_id: to_user_id,
  37 + reply_message_id: reply_message_id,
  38 + text: text
  39 + },
  40 + dataType: 'json',
  41 + headers: {
  42 + 'X-CSRF-TOKEN': $('[name="_token"]').val()
  43 + },
  44 + success: function(res){
  45 + if (res && res.success && res.url_redirect){
  46 + window.location.replace(res.url_redirect);
  47 + } else{
  48 + location.reload();
  49 + }
  50 + }
  51 + });
  52 + });
  53 + });
  54 +</script>
resources/views/svg/logo_icon.blade.php
... ... @@ -0,0 +1,5 @@
  1 +<div style="width: 56px;overflow: hidden;">
  2 + <svg style="width: 182px;height: 54px;color: #377d87;">
  3 + <use xlink:href="{{ asset('images/sprite.svg#logo') }}"></use>
  4 + </svg>
  5 +</div>
resources/views/workers/dialog.blade.php
... ... @@ -5,6 +5,13 @@
5 5 $(function(){
6 6 var chatbox_div = $('.chatbox__list');
7 7 chatbox_div.scrollTop(chatbox_div.prop("scrollHeight"));
  8 +
  9 + $('.admin-chat-answer').click(function(){
  10 + var modal = $('#answer_from_admin_chat_modal');
  11 +
  12 + modal.data('to-user-id', $(this).data('to-user-id'));
  13 + modal.data('message-id', $(this).data('message-id'));
  14 + });
8 15 });
9 16  
10 17 $(document).on('change', '#send_btn', function() {
... ... @@ -81,7 +88,14 @@
81 88 </a>
82 89 <div class="chatbox">
83 90 <div class="chatbox__toper">
84   - @if ($companion->is_worker)
  91 + @if($chat->is_admin_chat)
  92 + <div class="chatbox__toper-info messages__item-info">
  93 + @include('svg.logo_icon')
  94 + <div class="messages__item-text bold font20">
  95 + Администратор сайта
  96 + </div>
  97 + </div>
  98 + @elseif ($companion->is_worker)
85 99 <div class="chatbox__toper-info messages__item-info">
86 100 <div class="messages__item-photo">
87 101 <svg>
... ... @@ -104,7 +118,7 @@
104 118 </a>
105 119 @endif
106 120 @else
107   - <div class="chatbox__toper-info messages__item-info 222">
  121 + <div class="chatbox__toper-info messages__item-info">
108 122 <div class="messages__item-photo">
109 123 <svg>
110 124 <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
... ... @@ -151,7 +165,7 @@
151 165 <svg>
152 166 <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
153 167 </svg>
154   - @if ($companion->is_worker)
  168 + @if($companion->is_worker)
155 169 @if ((isset($companion->workers[0]->photo)) &&
156 170 (!empty($companion->workers[0]->photo)))
157 171 <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($companion->workers[0]->photo)) }}" alt="">
... ... @@ -174,29 +188,49 @@
174 188 </div>
175 189 @else
176 190 <div class="chatbox__item chatbox__item_reverse">
177   - <div class="chatbox__item-photo">
178   - <svg>
179   - <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
180   - </svg>
181   - @if ($sender->is_worker)
182   - @if ((isset($sender->workers[0]->photo)) &&
183   - (!empty($sender->workers[0]->photo)))
184   - <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->workers[0]->photo)) }}" alt="">
185   - @else
186   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
187   - @endif
  191 + <div class="@if(!$chat->is_admin_chat) chatbox__item-photo @endif">
  192 + @if($chat->is_admin_chat)
  193 + @include('svg.logo_icon')
188 194 @else
189   - @if ((isset($sender->employers[0]->logo)) &&
190   - (!empty($sender->employers[0]->logo)))
191   - <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->employers[0]->logo)) }}" alt="">
  195 + @if ($sender->is_worker)
  196 + @if ((isset($sender->workers[0]->photo)) &&
  197 + (!empty($sender->workers[0]->photo)))
  198 + <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->workers[0]->photo)) }}" alt="">
  199 + @else
  200 + <img src="{{ asset('images/default_man.jpg') }}" alt="">
  201 + @endif
192 202 @else
193   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
  203 + <svg>
  204 + <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
  205 + </svg>
  206 +
  207 + @if ((isset($sender->employers[0]->logo)) &&
  208 + (!empty($sender->employers[0]->logo)))
  209 + <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->employers[0]->logo)) }}" alt="">
  210 + @else
  211 + <img src="{{ asset('images/default_man.jpg') }}" alt="">
  212 + @endif
194 213 @endif
195 214 @endif
196   -
197 215 </div>
198 216 <div class="chatbox__item-body">
199   - <div class="chatbox__item-text">{{ $it->text }}</div>
  217 + <div class="chatbox__item-text">
  218 + @if($chat->is_admin_chat)
  219 + <button class="button admin-chat-answer" data-fancybox data-src="#answer_from_admin_chat_modal"
  220 + data-to-user-id="{{ $it->user_id }}" data-message-id="{{ $it->id }}"
  221 + >
  222 + Ответить
  223 + </button>
  224 + @endif
  225 +
  226 + {{ $it->text }}
  227 +
  228 + @if($it->reply_message_id)
  229 + <div class="reply-message">
  230 + {{ $it->reply_message->text }}
  231 + </div>
  232 + @endif
  233 + </div>
200 234 @if ((isset($it->file)) && (!empty($it->file)))
201 235 <a href="{{ asset(Storage::url($it->file)) }}" class="chatbox__item-text">
202 236 <svg>
... ... @@ -212,6 +246,7 @@
212 246 @endforeach
213 247 @endif
214 248 </div>
  249 + @if(!$chat->is_admin_chat)
215 250 <form action="{{ route('worker.test123') }}" class="chatbox__bottom" enctype="multipart/form-data" method="POST" >
216 251 @csrf
217 252 <label class="chatbox__bottom-file">
... ... @@ -232,6 +267,7 @@
232 267 </svg>
233 268 </button>
234 269 </form>
  270 + @endif
235 271 </div>
236 272 </div>
237 273 </div>
... ... @@ -239,4 +275,6 @@
239 275 </div>
240 276 </section>
241 277 </div>
  278 +
  279 + @include('modals.chats.answer_from_admin_chat')
242 280 @endsection
... ... @@ -514,7 +514,7 @@ Route::group([
514 514  
515 515 // 2 страница - Сообщения
516 516 Route::get('cabinet/messages/{type_message}', [WorkerController::class, 'messages'])->name('messages');
517   - Route::get('cabinet/dialog/{user1}/{user2}', [WorkerController::class, 'dialog'])->name('dialog');
  517 + Route::get('cabinet/dialog/{chat}', [WorkerController::class, 'dialog'])->name('dialog');
518 518 // 3 страница - Избранные вакансии
519 519 Route::get('cabinet/favorite', [WorkerController::class, 'favorite'])->name('favorite');
520 520 // Продолжение борьбы против колорадов - избранные вакансии
... ... @@ -617,7 +617,7 @@ Route::group([
617 617  
618 618 // 5 страница - Сообщения
619 619 Route::get('cabinet/messages/{type_message}', [EmployerController::class, 'messages'])->name('messages');
620   - Route::get('cabinet/dialog/{user1}/{user2}', [EmployerController::class, 'dialog'])->name('dialog');
  620 + Route::get('cabinet/dialog/{chat}', [EmployerController::class, 'dialog'])->name('dialog');
621 621 Route::post('cabinet/send-message', [EmployerController::class, 'send_message'])->name('send_message');
622 622 Route::post('test123', [EmployerController::class, 'test123'])->name('test123');
623 623  
... ... @@ -659,3 +659,5 @@ Route::group([
659 659  
660 660 Route::get('TestWorker', [WorkerController::class, 'TestWorker'])->name('TestWorker');
661 661  
  662 +Route::post('send_message', [HomeController::class, 'send_message'])->name('send_message');
  663 +