diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index 6ea6e25..3f379e6 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use App\Classes\RusDate; use App\Classes\Tools; +use App\Http\Requests\BaseUser_min_Request; +use App\Http\Requests\BaseUserRequest; use App\Http\Requests\FlotRequest; use App\Http\Requests\MessagesRequiest; use App\Http\Requests\VacancyRequestEdit; @@ -66,6 +68,22 @@ class EmployerController extends Controller ->with('success', 'Вы вышли из личного кабинета'); } + public function employer_info() { + // код юзера + $user_info = Auth()->user(); + // вьюшка для вывода данных + return view('employers.info', compact('user_info')); + } + + public function employer_info_save(User_Model $user, BaseUser_min_Request $request) { + // Все данные через реквест + $all = $request->all(); + unset($all['_token']); + // обновление + $user->update($all); + return redirect()->route('employer.employer_info'); + } + public function cabinet() { $id = Auth()->user()->id; $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> @@ -300,48 +318,49 @@ class EmployerController extends Controller $count_output = $messages_output->count(); if ($type_message == 'input') { - $messages = $messages_input->paginate(15); + $messages = $messages_input->paginate(5); } if ($type_message == 'output') { - $messages = $messages_output->paginate(15); + $messages = $messages_output->paginate(5); } + //dd($user_id, $messages[2]->vacancies); + //jobs); + return view('employers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id')); } // Диалог между пользователями - public function dialog(User_Model $user1, User_Model $user2) { + public function dialog(Request $request, User_Model $user1, User_Model $user2) { + // Получение параметров. + if ($request->has('ad_employer')){ + $ad_employer = $request->get('ad_employer'); + } else { + $ad_employer = 0; + } + if (isset($user2->id)) { $companion = User_Model::query()->with('workers')-> with('employers')-> where('id', $user2->id)->first(); } - $Messages = Message::query()->with('response')->where(function($query) use ($user1, $user2) { + $Messages = Message::query()-> + where('ad_employer_id', '=', $ad_employer)-> + where(function($query) use ($user1, $user2) { $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); })->orWhere(function($query) use ($user1, $user2) { $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); - })->OrderBy('created_at')->get(); + })->where('ad_employer_id', '=', $ad_employer)->OrderBy('created_at')->get(); $id_vac = $Messages[$Messages->count() - 1]->ad_employer_id; - /*foreach ($Messages as $it) { - if (isset($it->response)) { - foreach ($it->response as $r) { - if (isset($r->ad_employer_id)) { - $id_vac = $r->ad_employer_id; - break; - } - } - } - if (!is_null($id_vac)) break; - } - */ - $ad_employer = null; - if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); + //$ad_employer = null; + //if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); $sender = $user1; - return view('employers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer')); + + return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages')); } // Регистрация работодателя diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 4ae9fb6..9ee6b5d 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -350,13 +350,13 @@ class MainController extends Controller 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' ], ]; - $validator = Validator::make($request->all(), $rules, $messages); - - if ($validator->fails()) { - return json_encode(Array("ERROR" => "Email или пароль невалидный!")); - //redirect()->route('index')->with('Error', "Email или пароль невалидный"); + $user_id = $request->user()->id; + if ($user_id > 0) + return json_encode(Array("ERROR" => "Email или пароль невалидный!")); + else + return redirect()->route('index')->with('Error', "Email или пароль невалидный"); } else { $credentials = $request->only('email', 'password'); diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 9d014f8..d011281 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -373,12 +373,13 @@ class WorkerController extends Controller $count_output = $messages_output->count(); if ($type_message == 'input') { - $messages = $messages_input->paginate(15); + $messages = $messages_input->paginate(5); } if ($type_message == 'output') { - $messages = $messages_output->paginate(15); + $messages = $messages_output->paginate(5); } + // Вернуть все 100% return view('workers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id')); } diff --git a/app/Http/Requests/BaseUser_min_Request.php b/app/Http/Requests/BaseUser_min_Request.php new file mode 100644 index 0000000..809d9f1 --- /dev/null +++ b/app/Http/Requests/BaseUser_min_Request.php @@ -0,0 +1,49 @@ + + */ + public function rules() + { + return [ + //'name' => 'required|min:3|max:255', + 'surname' => 'required|min:3|max:255', + 'name_man' => 'required|min:3|max:255', + ]; + } + + public function messages() { + return [ + 'required' => 'Поле :attribute обязательно для ввода', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + 'email' => 'Введите корректный емайл', + 'unique' => 'Емайл должен быть уникальным', + + ]; + } +} diff --git a/app/Models/Message.php b/app/Models/Message.php index 295396b..2c68d53 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -34,15 +34,8 @@ class Message extends Model return $this->belongsTo(User::class, 'to_user_id'); } - /* - * Связь модели Сообщения (Message) с моделью Отклик на Вакансию (Ad_response) - */ - public function response() { - return $this->hasMany(ad_response::class); - } - // Связь модели Сообщения (Message) с моделью Вакансии (Ad_employer) public function vacancies() { - return $this->belongsToMany(Ad_employer::class, 'ad_responses'); + return $this->belongsTo(Ad_employer::class, 'ad_employer_id', 'id'); } } diff --git a/database/migrations/2024_04_17_060549_alter_table_messages.php b/database/migrations/2024_04_17_060549_alter_table_messages.php new file mode 100644 index 0000000..9f8ac08 --- /dev/null +++ b/database/migrations/2024_04_17_060549_alter_table_messages.php @@ -0,0 +1,32 @@ +integer('flag_new_from')->default(1); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('messages', function (Blueprint $table) { + $table->dropColumn('flag_new_from'); + }); + } +}; diff --git a/resources/views/employers/cabinet45.blade.php b/resources/views/employers/cabinet45.blade.php index 0c57d9c..0473a9c 100644 --- a/resources/views/employers/cabinet45.blade.php +++ b/resources/views/employers/cabinet45.blade.php @@ -141,6 +141,43 @@ @enderror + +