diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index aa255a3..d3020ff 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -10,6 +10,7 @@ use App\Http\Requests\MessagesRequiest; use App\Http\Requests\VacancyRequestEdit; use App\Mail\MailCreateEmployer; use App\Mail\MailSotrudnichestvo; +use App\Mail\MassSendingMessages; use App\Mail\SendAllMessages; use App\Models\Ad_employer; use App\Models\ad_response; @@ -21,6 +22,7 @@ use App\Models\Job_title; use App\Models\Like_worker; use App\Models\Message; use App\Models\Worker; +use App\Models\MessagesRequests; use Carbon\Carbon; use Illuminate\Auth\Events\Registered; use Illuminate\Database\Eloquent\Builder; @@ -736,8 +738,16 @@ class EmployerController extends Controller public function send_all_messages() { $id = Auth()->user()->id; $sending = Employer::query()->where('user_id', '=', "$id")->first(); + + $job_titles = Job_title::query() + ->where('is_remove', '=', 0) + ->where('is_bd', '=', 1) + ->orderByDesc('sort') + ->get() + ; + if ($sending->sending_is) - return view('employers.send_all'); + return view('employers.send_all', compact('job_titles')); else return view('employers.send_all_danger'); } @@ -745,14 +755,25 @@ class EmployerController extends Controller // Отправка сообщений для информации public function send_all_post(Request $request) { $data = $request->all(); + $data['user'] = Auth()->user(); - $emails = User_Model::query()->where('is_worker', '1')->get(); + $id = MessagesRequests::create([ + 'user_id' => Auth()->user()->id, + 'job_titles' => json_encode($data['job_title_ids']), + 'text' => $data['message_text'], + ]); + + if (!empty($id)){ + Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data)); + } + + /*$emails = User_Model::query()->where('is_worker', '1')->get(); foreach ($emails as $e) { Mail::to($e->email)->send(new SendAllMessages($data)); - } + }*/ - return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены'); + return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.'); } // База резюме diff --git a/app/Mail/MassSendingMessages.php b/app/Mail/MassSendingMessages.php new file mode 100644 index 0000000..4eb5f73 --- /dev/null +++ b/app/Mail/MassSendingMessages.php @@ -0,0 +1,44 @@ +data = $data; + } + + public function envelope(): Envelope + { + return new Envelope( + subject: 'Запрос на рассылку сообщений', + ); + } + + public function build() + { + + // Вернуть все данные + return $this->view('emails.added_mass_sending_messages', ['data' => $this->data]); + } + + + public function attachments(): array + { + return []; + } +} diff --git a/app/Models/MessagesRequests.php b/app/Models/MessagesRequests.php new file mode 100644 index 0000000..83d334f --- /dev/null +++ b/app/Models/MessagesRequests.php @@ -0,0 +1,19 @@ +id(); + $table->bigInteger('user_id')->nullable(false); + $table->text('job_titles')->nullable(false); + $table->text('text')->nullable(); + $table->dateTime('is_rejected')->nullable(true); + $table->dateTime('is_sent')->nullable(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('messages_requests'); + } +}; diff --git a/resources/views/emails/added_mass_sending_messages.blade.php b/resources/views/emails/added_mass_sending_messages.blade.php new file mode 100644 index 0000000..61191a5 --- /dev/null +++ b/resources/views/emails/added_mass_sending_messages.blade.php @@ -0,0 +1,3 @@ +
Контактные данные
-Все поля обязательны для заполнения *
-Ваше сообщение
-