diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 30daf91..ea33764 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -162,6 +162,55 @@ class AdminController extends Controller } } + //Страница профиль пользователя - форма + public function profile_user(User $user) { + $visible = false; + if($user->is_worker) { + $caption = "Карточка работника"; + if (isset($user->workers[0]->id)) { + $link = route('admin.worker-profile', ['worker' => $user->workers[0]->id]); + $visible = true; + } else { + $link = ""; + } + + } else { + $caption = "Карточка работодателя"; + if (isset($user->employers[0]->id)) { + + $link = route('admin.employer-profile', ['employer' => $user->employers[0]->id]); + $visible = true; + } else { + $link = ""; + } + } + + return view('admin.users.profile', compact('user', 'visible', 'link', 'caption')); + } + + //Страница профиль пользователя - сохранение формы + public function store_profile_user(User $user, Request $request) { + $rules = [ + 'name' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'email' => 'Это поле должно быть определено, как Email' + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.user-profile', ['user' => $user->id]) + ->withErrors($validator); + } else { + $user->update($request->all()); + return redirect()->route('admin.user-profile', ['user' => $user->id]) + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.user-profile', ['user' => $user->id]); + } + + // Страница профиль админа - форма public function profile() { $id = Auth::user()->id; $user = User::find($id); @@ -169,18 +218,82 @@ class AdminController extends Controller return view('admin.profile', compact('user')); } + // Страница профиль админа - сохранение формы public function store_profile(Request $request) { $id = Auth::user()->id; $user = User::find($id); + $rules = [ + 'name' => 'required|min:3', + 'email' => 'required|email|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'email' => 'Это поле должно быть определено, как Email' + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.profile') + ->withErrors($validator); + } else { + $user->update($request->all()); + return redirect()->route('admin.profile') + ->with('success', 'Данные были успешно сохранены'); + } return redirect()->route('admin.profile'); } + // Форма смены пароля администоратора + public function profile_password() { + $id = Auth::user()->id; + $user = User::find($id); + $username = $user->name; + + return view('admin.password', compact('username')); + } + + // Сохранение формы смены пароля администоратора + public function profile_password_new(Request $request) { + + $rules = [ + 'old_password' => 'required|min:6', //|current_password:api', + 'password' => 'required|min:6|confirmed', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'confirmed' => 'Пароли не совпадают' + ]; + + $validator = Validator::make($request->all(), $rules, $messages); + + if (! Hash::check($request->old_password, $request->user()->password)) { + return back()->withErrors([ + 'old_password' => ['Неверный предыдущий пароль'] + ]); + } + + if ($validator->fails()) { + return redirect()->route('admin.password') + ->withErrors($validator); + } else { + $params = $request->all(); + // устанавливаем новый пароль для пользователя + User::where('id', Auth::id()) + ->update(['password' => Hash::make($request->password)]); + session()->flash('success', 'Успешно изменен пароль!'); + + return redirect()->route('admin.password'); + } + } + + // Страница конфигурация сайта - форма public function config_form() { $config = Company::find(1); return view('admin.config', compact('config')); } + // Страница конфигурация сайта - сохранение формы public function store_config(CompanyRequest $request) { $config = Company::find(1); diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index 8305025..1ecb86a 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Employer; use App\Models\User; use Illuminate\Http\Request; @@ -22,4 +23,8 @@ class EmployersController extends Controller return view('admin.employer.index', compact('users')); } } + + public function form_update_employer(Employer $employer) { + return view('admin.employer.edit', compact('employer')); + } } diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php index afa5294..dcc857f 100644 --- a/app/Http/Controllers/Admin/WorkersController.php +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\User; +use App\Models\Worker; use Illuminate\Http\Request; class WorkersController extends Controller @@ -23,4 +24,8 @@ class WorkersController extends Controller return view('admin.worker.index', compact('users')); } } + + public function form_update_worker(Worker $worker) { + return view('admin.worker.edit'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 99e5e2c..6d5de93 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -59,7 +59,7 @@ class User extends Authenticatable * users - employers */ public function employers() { - return $this->hasMany(Employer::class); + return $this->hasMany(Employer::class, 'user_id'); } /* @@ -67,7 +67,7 @@ class User extends Authenticatable * users - workers */ public function workers() { - return $this->hasMany(Worker::class); + return $this->hasMany(Worker::class, 'user_id'); } /* diff --git a/resources/views/admin/employer/edit.blade.php b/resources/views/admin/employer/edit.blade.php new file mode 100644 index 0000000..d9305b2 --- /dev/null +++ b/resources/views/admin/employer/edit.blade.php @@ -0,0 +1,320 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование работодателя']) + +@section('content') +