From eb8596db66c772ba6f16740ed42179b0ab051f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Tue, 31 Oct 2023 18:23:45 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=D0=B0?= =?UTF-8?q?=D0=BA=D0=B0=D0=BD=D1=81=D0=B8=D0=B8,=20=D0=BE=D0=B1=D1=80=D0=B0=D0?= =?UTF-8?q?=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5,=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0?= =?UTF-8?q?=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Classes/Tools.php | 25 +++++ .../Controllers/Admin/Ad_EmployersController.php | 37 ++++++- app/Http/Controllers/Admin/AdminController.php | 39 ++++--- app/Http/Controllers/Admin/EducationController.php | 13 ++- app/Http/Controllers/Admin/EmployersController.php | 17 ++- app/Models/Employer.php | 4 + app/Models/User.php | 8 ++ .../2023_10_31_060833_alter_table_employers.php | 32 ++++++ resources/views/admin/ad_employers/add.blade.php | 104 ++++++++++++++++++ resources/views/admin/ad_employers/edit.blade.php | 11 ++ resources/views/admin/ad_employers/index.blade.php | 20 +++- resources/views/admin/education/edit.blade.php | 4 +- resources/views/admin/education/form.blade.php | 115 +++++++++----------- resources/views/admin/employer/index.blade.php | 7 +- resources/views/admin/register.blade.php | 8 +- resources/views/admin/users/index.blade.php | 2 +- routes/web.php | 7 +- 17 files changed, 350 insertions(+), 103 deletions(-) create mode 100644 app/Classes/Tools.php create mode 100644 database/migrations/2023_10_31_060833_alter_table_employers.php create mode 100644 resources/views/admin/ad_employers/add.blade.php diff --git a/app/Classes/Tools.php b/app/Classes/Tools.php new file mode 100644 index 0000000..6624d71 --- /dev/null +++ b/app/Classes/Tools.php @@ -0,0 +1,25 @@ +active()->get(); + return view('admin.ad_employers.add', compact('job_titles')); } /** @@ -93,7 +93,31 @@ class Ad_EmployersController extends Controller */ public function store(Request $request) { - // + $params = $request->all(); + unset($params->position_work); + $rules = [ + 'name' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + ]; + $validator = Validator::make($params, $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.add-ad-employers') + ->withErrors($validator); + } else { + $ad_employer = new Ad_employer(); + $params['employer_id'] = 1; + $data_ad = $ad_employer->create($params); + $data_ad->jobs()->sync($request->position_work); + //$ad_employer->jobs()->sync($request->position_work); + + + return redirect()->route('admin.ad-employers') + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.ad-employers'); } /** @@ -165,6 +189,9 @@ class Ad_EmployersController extends Controller */ public function destroy(Ad_employer $ad_employer) { - // + $ad_employer->is_remove = 1; + $ad_employer->save(); + + return redirect()->route('admin.ad-employers'); } } diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 41f1386..b93ba43 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin; +use App\Classes\Tools; use App\Http\Controllers\Controller; use App\Http\Requests\CompanyRequest; use App\Models\Company; @@ -28,12 +29,15 @@ class AdminController extends Controller } public function register() { - return view('admin.register'); + $code_emp = Tools::generator_id(10); + return view('admin.register', compact('code_emp')); } public function create(Request $request) { - $rules = [ + $params = $request->all(); + unset($params['code_emp']); + $rules = [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', @@ -54,23 +58,30 @@ class AdminController extends Controller ], ]; - $validator = Validator::make($request->all(), $rules, $messages); + $validator = Validator::make($params, $rules, $messages); if ($validator->fails()) { - return back()->withErrors($validator)->withInput(); //->route('admin.register') + return back()->withErrors($validator)->withInput(); } else { - $params = $request->all(); - - User::create([ - 'name' => $request->name, - 'email' => $request->email, - 'password' => Hash::make($request->password), - 'pubpassword' => base64_encode($request->password), - 'admin' => '1', - 'email_verified_at' => Carbon::now() + try { + $user = User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'password' => Hash::make($request->password), + 'pubpassword' => base64_encode($request->password), + 'admin' => '1', + 'is_worker' => '0', + 'email_verified_at' => Carbon::now() + ]); + } finally { + $emp = Employer::create([ + 'name_company' => 'Администратор', + 'user_id' => $user->id, + 'code' => $request->code_emp + ]); + } - ]); return redirect() ->route('admin.login') ->with('success', 'Вы успешно зарегистрировались'); diff --git a/app/Http/Controllers/Admin/EducationController.php b/app/Http/Controllers/Admin/EducationController.php index e45ea75..c34bd73 100644 --- a/app/Http/Controllers/Admin/EducationController.php +++ b/app/Http/Controllers/Admin/EducationController.php @@ -70,14 +70,18 @@ class EducationController extends Controller */ public function edit(Education $education) { - $program1 = ProgramEducation::query()->where('education_id', '=', $education->id) + /*$program1 = ProgramEducation::query()->where('education_id', '=', $education->id) ->where('level', '=', '1')->get(); $program2 = ProgramEducation::query()->where('education_id', '=', $education->id) ->where('level', '=', '2')->get(); $program3 = ProgramEducation::query()->where('education_id', '=', $education->id) ->where('level', '=', '3')->get(); + */ - return view('admin.education.edit', compact('education', 'program1', 'program2', 'program3')); + $program = ProgramEducation::query()->where('education_id', '=', $education->id) + ->orderBy('level')->get(); + + return view('admin.education.edit', compact('education', 'program')); } /** @@ -113,8 +117,9 @@ class EducationController extends Controller return redirect()->route('admin.education.index'); } - public function add_program(Education $education, int $level) { - $id_education = $education->id; + public function add_program(Request $request) { + $id_education = $request->id; + $level = $request->level; return view('admin.education.program', compact('id_education', 'level')); } diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index f982df8..caa16b6 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -27,7 +27,7 @@ class EmployersController extends Controller $users = User::with('employers')->select(['users.*','users.id as usr_id', 'emp.id as emp_id', 'emp.logo as emp_logo', 'emp.*']) ->join('employers as emp','emp.user_id','users.id') - ->where('users.is_worker', '0')->Realuser(); + ->where('users.is_worker', '0')->Realuser()->Notadmin(); $all_employer = $users->count(); $find_cat = ""; @@ -57,7 +57,11 @@ class EmployersController extends Controller if ($request->ajax()) { return view('admin.employer.index_ajax', compact('users')); } else { - return view('admin.employer.index', compact('users', 'find_key', 'find_cat', 'all_employer', 'select_category')); + return view('admin.employer.index', compact('users', + 'find_key', + 'find_cat', + 'all_employer', + 'select_category')); } } @@ -144,10 +148,17 @@ class EmployersController extends Controller public function delete_employer(Employer $employer, User $user) { try { if (!empty($employer)) { - $employer->ads()->delete(); if (!empty($employer->logo)) { Storage::delete($employer->logo); } + + foreach($employer->ads as $ad) { + $ads = Ad_employer::find($ad->id); + $ads->employer_id = 2; + $ads->is_remove = 1; + $ads->save(); + } + $employer->delete(); } } finally { diff --git a/app/Models/Employer.php b/app/Models/Employer.php index 78cc299..c697ec2 100644 --- a/app/Models/Employer.php +++ b/app/Models/Employer.php @@ -27,6 +27,10 @@ class Employer extends Model 'oficial_status', 'social_is', 'sending_is', + 'category', + 'comment_admin', + 'code', + 'status_hidden' ]; /* diff --git a/app/Models/User.php b/app/Models/User.php index cc5ef62..40da22e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -143,4 +143,12 @@ class User extends Authenticatable return $query->where('is_bd', '=', '0'); } + public function scopeAdmin($query) { + return $query->where('admin', '=', '1'); + } + + public function scopeNotadmin($query) { + return $query->where('admin', '=', '0'); + } + } diff --git a/database/migrations/2023_10_31_060833_alter_table_employers.php b/database/migrations/2023_10_31_060833_alter_table_employers.php new file mode 100644 index 0000000..ffe55d8 --- /dev/null +++ b/database/migrations/2023_10_31_060833_alter_table_employers.php @@ -0,0 +1,32 @@ +string('code', 100)->nullable(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('employers', function (Blueprint $table) { + $table->dropColumn('code'); + }); + } +}; diff --git a/resources/views/admin/ad_employers/add.blade.php b/resources/views/admin/ad_employers/add.blade.php new file mode 100644 index 0000000..3b4441d --- /dev/null +++ b/resources/views/admin/ad_employers/add.blade.php @@ -0,0 +1,104 @@ +@extends('layout.admin', ['title' => 'Админка - Добавление вакансии']) + +@section('script') + +@endsection + +@section('content') +

+ Добавление вакансии +

+
+ @csrf +
+ + +
+ + + +
+ + + +
+
+ + Назад +
+
+
+
+@endsection diff --git a/resources/views/admin/ad_employers/edit.blade.php b/resources/views/admin/ad_employers/edit.blade.php index c496a79..b61bc62 100644 --- a/resources/views/admin/ad_employers/edit.blade.php +++ b/resources/views/admin/ad_employers/edit.blade.php @@ -39,6 +39,17 @@ @endforeach +
+ +