diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 3f19485..c5c97f5 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -5,10 +5,13 @@ namespace App\Http\Controllers; use App\Classes\RusDate; use App\Models\Ad_employer; use App\Models\Category; +use App\Models\Dop_info; use App\Models\Employer; +use App\Models\infobloks; use App\Models\Job_title; use App\Models\Message; use App\Models\reclame; +use App\Models\sertification; use App\Models\Static_worker; use App\Models\User; use App\Models\User as User_Model; @@ -20,6 +23,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; class WorkerController extends Controller @@ -88,19 +92,90 @@ class WorkerController extends Controller public function cabinet() { $id = Auth()->user()->id; - $Worker = Worker::query()->with('sertificate')-> + $Worker = Worker::query()->with('users')->with('sertificate')->with('prev_company')-> with('infobloks')->with('place_worker')-> WhereHas('users', function (Builder $query) use ($id) {$query->Where('id', $id); })->get(); - dd($Worker); - return view('workers.cabinet', compact('Worker')); + + $Job_titles = Job_title::query()->OrderBy('name')->get(); + $Infoblocks = infobloks::query()->OrderBy('name')->get(); + + return view('workers.cabinet', compact('Worker', 'Job_titles', 'Infoblocks')); } // Сохранение данных public function cabinet_save(Worker $worker, Request $request) { + $id = $worker->id; + $params = $request->all(); + + $job_title_id = $request->get('job_title_id'); + + unset($params['new_diplom']); + unset($params['new_data_begin']); + unset($params['new_data_end']); + unset($params['new_job_title']); + unset($params['new_teplohod']); + unset($params['new_GWT']); + unset($params['new_KBT']); + unset($params['new_Begin_work']); + unset($params['new_End_work']); + unset($params['new_name_company']); + + $rules = [ + 'surname' => ['required', 'string', 'max:255'], + 'name_man' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255'], + + ]; + + $messages = [ + 'required' => 'Укажите обязательное поле', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'integer' => 'Поле «:attribute» должно быть :min или больше', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'integer' => 'Поле «:attribute» должно быть :max или меньше', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ] + ]; + + $validator = Validator::make($params, $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('worker.cabinet')->withErrors($validator); + } else { + + if ($request->has('photo')) { + if (!empty($Worker->photo)) { + Storage::delete($Worker->photo); + } + $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); + } + + if ($request->has('file')) { + if (!empty($Worker->file)) { + Storage::delete($Worker->file); + } + $params['file'] = $request->file('file')->store("worker/$id", 'public'); + } + + $id_wor = $worker->update($params); + + $use = User_Model::find($id_wor); + $use->surname = $request->get('surname'); + $use->name_man = $request->get('name_man'); + $use->surname2 = $request->get('surname2'); + + $use->save(); + $worker->job_titles()->sync($job_title_id); + return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); + } } // Сообщения данные @@ -133,11 +208,9 @@ class WorkerController extends Controller // Избранный public function favorite() { - dd('dgfghfghfgh'); return view('workers.favorite'); } - // Сменить пароль public function new_password() { @@ -360,5 +433,64 @@ class WorkerController extends Controller return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer')); } + + // Даунлоады + public function download(Worker $worker) { + + } + + // Поднятие анкеты + public function up(Worker $worker) { + $worker->updated_at = Carbon::now(); + $worker->save(); + return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); + } + + // Добавление сертификата + public function add_serificate(Request $request) { + $params = $request->all(); + $params['date_begin'] = date('d.m.Y', strtotime($params['date_begin'])); + $params['end_begin'] = date('d.m.Y', strtotime($params['end_begin'])); + $Sertificate = new sertification(); + $Sertificate->create($params); + $Docs = sertification::query()->where('worker_id', $request->get('worker_id'))->get(); + return view('ajax.documents', compact('Docs')); + } + + + // Удалить сертификат + public function delete_sertificate(sertification $doc) { + $doc->delete(); + + return redirect()->route('worker.cabinet'); + } + + // Добавление диплома + public function add_diplom_ajax(Request $request) { + // конец + $params = $request->all(); + $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); + + if ($count == 0) $dop_info = Dop_info::create($params); + $Infoblocks = infobloks::query()->get(); + $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); + $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); + return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); + } + + // Добавление диплома без ajax + public function add_diplom(Worker $worker) { + $worker_id = $worker->id; + $Infoblocks = infobloks::query()->get(); + return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); + } + // Сохранить + // Сохраняю диплом + public function add_diplom_save(Request $request) { + $params = $request->all(); + $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); + if ($count == 0) $dop_info = Dop_info::create($params); + return redirect()->route('worker.cabinet'); + } } diff --git a/app/Http/Requests/VacansiaRequiest.php b/app/Http/Requests/VacansiaRequiest.php index 712a28e..fe18124 100644 --- a/app/Http/Requests/VacansiaRequiest.php +++ b/app/Http/Requests/VacansiaRequiest.php @@ -48,14 +48,33 @@ class VacansiaRequiest extends FormRequest ], 'salary' => [ + 'numeric', 'min:3', 'max:255', ], + 'min_salary' => [ + 'numeric', + 'min:0', + 'max:9999999', + ], + + 'max_salary' => [ + 'numeric', + 'min:0', + 'max:9999999', + ], + 'city' => [ 'min:3', 'max:255', ], + + 'job_title_id' => [ + 'numeric', + 'min:1', + 'max:9999999' + ] ]; } diff --git a/app/Models/Dop_info.php b/app/Models/Dop_info.php new file mode 100644 index 0000000..09a8a5a --- /dev/null +++ b/app/Models/Dop_info.php @@ -0,0 +1,19 @@ +hasMany(Job_title::class, 'id'); + return $this->belongsToMany(Job_title::class, 'title_workers'); } //Связь Работника с опытом работы (1 - 0-0) diff --git a/app/Models/sertification.php b/app/Models/sertification.php index 4ff3ea3..091c31e 100644 --- a/app/Models/sertification.php +++ b/app/Models/sertification.php @@ -8,4 +8,12 @@ use Illuminate\Database\Eloquent\Model; class sertification extends Model { use HasFactory; + + protected $fillable = [ + 'date_begin', + 'end_begin', + 'worker_id', + 'name', + 'education' + ]; } diff --git a/database/migrations/2024_03_05_100903_create_title_workers_table.php b/database/migrations/2024_03_05_100903_create_title_workers_table.php new file mode 100644 index 0000000..167bdf7 --- /dev/null +++ b/database/migrations/2024_03_05_100903_create_title_workers_table.php @@ -0,0 +1,33 @@ +id(); + $table->bigInteger('worker_id')->nullable(false); + $table->bigInteger('jib_title_id')->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('title_workers'); + } +}; diff --git a/resources/views/ajax/documents.blade.php b/resources/views/ajax/documents.blade.php new file mode 100644 index 0000000..1f7596b --- /dev/null +++ b/resources/views/ajax/documents.blade.php @@ -0,0 +1,37 @@ +@if ($Docs->count()) + @php $i = 0; @endphp + @foreach($Docs as $it) +