diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index b88ba5e..a92e17a 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -521,23 +521,12 @@ class EmployerController extends Controller $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { - $chat = Chat::where('user_id', $user1) - ->where('to_user_id', $user2) - ->where('is_removed', 0) - ->first() - ; - if ($chat->id){ - return redirect()->route('employer.dialog', ['chat' => $chat->id])->withErrors($validator); - } else { - return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); - } - - } else { - $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); + return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); + } - return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]); + $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); + return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]); - } } //Избранные люди @@ -756,25 +745,23 @@ class EmployerController extends Controller { $params = $request->all(); - $id = $params['_user_id']; + $id = $params['send_user_id']; $message_params = [ - 'title' => $params['title'], - 'text' => $params['text'], - 'ad_employer_id' => $params['_vacancy'], + 'title' => $params['send_title'], + 'text' => $params['send_text'], + 'ad_employer_id' => $params['send_vacancy'], 'flag_new' => 1 ]; - dd($params); - - Message::add_message( + $message = Message::add_message( $request, - $params['_user_id'], - $params['_to_user_id'], + $params['send_user_id'], + $params['send_to_user_id'], $message_params, file_store_path: "worker/$id" ); - return redirect()->route('employer.messages', ['type_message' => 'output']); + return redirect()->route('employer.dialog', ['chat' => $message->chat_id_to]); } // Восстановление пароля diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 59ed51a..9d9b8fd 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -964,31 +964,32 @@ class WorkerController extends Controller } //Отправка нового сообщения - public function new_message(Request $request) { + public function new_message(Request $request) + { $params = $request->all(); - $id = $params['send_user_id']; + $id = $params['_user_id']; $message_params = [ - 'title' => $params['send_title'], - 'text' => $params['send_text'], - 'ad_employer_id' => $params['send_vacancy'], + 'title' => $params['title'], + 'text' => $params['text'], + 'ad_employer_id' => $params['_vacancy'], 'flag_new' => 1 ]; - $message = Message::add_message( + $message = Message::add_message( $request, - $params['send_user_id'], - $params['send_to_user_id'], + $params['_user_id'], + $params['_to_user_id'], $message_params, file_store_path: "worker/$id" ); $data['message_id'] = $message->id; - $data['ad_employer_id'] = $params['send_vacancy']; - $data['job_title_id'] = $params['send_job_title_id']; + $data['ad_employer_id'] = $params['_vacancy']; + //$data['job_title_id'] = $params['_job_title_id']; $data['flag'] = 1; - $ad_responce = ad_response::create($data); - return redirect()->route('worker.messages', ['type_message' => 'output']); + ad_response::create($data); + return redirect()->route('worker.dialog', ['chat' => $message->chat_id_from]); } diff --git a/app/Models/Message.php b/app/Models/Message.php index e6e4886..26ff776 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -55,7 +55,6 @@ class Message extends Model string $file_store_path = '/', bool $is_admin_chat = false ) { - dd($request->all()); $message_params['user_id'] = $user_id; $message_params['to_user_id'] = $to_user_id; if ($request && $request->has('file')) { diff --git a/resources/views/modals/send_message_low_profile_percent.blade.php b/resources/views/modals/send_message_low_profile_percent.blade.php index 04ae0ea..7cd53fd 100644 --- a/resources/views/modals/send_message_low_profile_percent.blade.php +++ b/resources/views/modals/send_message_low_profile_percent.blade.php @@ -49,10 +49,6 @@ $('#_to_user_id').val($(this).data('tuid')); $('#_vacancy').val($(this).data('vacancy')); $('#_user_id').val($(this).data('uid')); - - console.log($(this).data('uid'), $('#_user_id')) - //console.log($('#_to_user_id')) - //console.log($('#_vacancy')) }); diff --git a/routes/web.php b/routes/web.php index d9b7144..8f31e33 100644 --- a/routes/web.php +++ b/routes/web.php @@ -582,7 +582,9 @@ Route::group([ Route::get('кабинет/delete_document/{doc}', [WorkerController::class, 'delete_document'])->name('delete_document'); // Отправка сообщения работодателю от соискателя - Route::post('сообщение/', [WorkerController::class, 'new_message'])->name('new_message'); + Route::post('сообщение/', [WorkerController::class, 'new_message']) + ->withoutMiddleware('is_worker') + ->name('new_message'); }); // Личный кабинет работодателя