diff --git a/app/Http/Controllers/Admin/CategoryController.php b/app/Http/Controllers/Admin/CategoryController.php new file mode 100644 index 0000000..c98d2e6 --- /dev/null +++ b/app/Http/Controllers/Admin/CategoryController.php @@ -0,0 +1,95 @@ +paginate(15); + return view('admin.category.index', compact('category')); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return view('admin.category.add'); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(CategoryRequest $request) + { + Category::create($request->all()); + return redirect()->route('admin.categories.index'); + } + + /** + * Display the specified resource. + * + * @param \App\Models\Category $category + * @return \Illuminate\Http\Response + */ + public function show(Category $category) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Models\Category $category + * @return \Illuminate\Http\Response + */ + public function edit(Category $category) + { + return view('admin.category.edit', compact('category')); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Models\Category $category + * @return \Illuminate\Http\Response + */ + public function update(CategoryRequest $request, Category $category) + { + $category->update($request->all()); + return redirect()->route('admin.categories.index'); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Models\Category $category + * @return \Illuminate\Http\Response + */ + public function destroy(Category $category) + { + if (Auth::user()->id == 1) { + $category->delete(); + } + return redirect()->route('admin.categories.index'); + } +} diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index 1ecb86a..005d67a 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; use App\Models\Employer; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Validator; class EmployersController extends Controller { @@ -27,4 +29,62 @@ class EmployersController extends Controller public function form_update_employer(Employer $employer) { return view('admin.employer.edit', compact('employer')); } + + public function update_employer(Employer $employer, Request $request) + { + $params = $request->all(); + unset($params['logo']); + unset($params['telephone']); + unset($params['email']); + unset($params['address']); + unset($params['site']); + + $rules = [ + 'name' => 'required|string|max:255', + ]; + + $messages = [ + 'required' => 'Укажите обязательное поле «:attribute»', + 'confirmed' => 'Пароли не совпадают', + 'email' => 'Введите корректный email', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + ]; + + $validator = Validator::make($params, $rules, $messages); + + if ($validator->fails()) { + return back()->withErrors($validator)->withInput(); //->route('admin.register') + + } else { + + //$user = User::find($employer->user_id); + $user_id = $employer->user_id; + $employer->telephone = $request->telephone; + $employer->email = $request->email; + $employer->address = $request->address; + $employer->site = $request->site; + $employer->text = $request->text; + + if ($request->has('logo')) { + if (!empty($employer->logo)) { + Storage::delete($employer->logo); + } + $employer->logo = $request->file('logo')->store("employer/$user_id", 'public'); + } + $employer->save(); + + $user = User::find($user_id); + $user->update($params); + + return redirect()->route('admin.employer-profile', ['employer' => $employer->id]) + ->with('success', 'Данные были успешно сохранены'); + } + } } diff --git a/app/Http/Requests/CategoryRequest.php b/app/Http/Requests/CategoryRequest.php new file mode 100644 index 0000000..cb2af7f --- /dev/null +++ b/app/Http/Requests/CategoryRequest.php @@ -0,0 +1,45 @@ + + */ + public function rules() + { + return [ + 'name' => '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 Кбайт' + ], + + ]; + } +} diff --git a/app/Models/Category.php b/app/Models/Category.php index c9d6222..846941f 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -8,4 +8,8 @@ use Illuminate\Database\Eloquent\Model; class Category extends Model { use HasFactory; + + protected $fillable = [ + 'name', + ]; } diff --git a/resources/views/admin/category/add.blade.php b/resources/views/admin/category/add.blade.php new file mode 100644 index 0000000..d8810ef --- /dev/null +++ b/resources/views/admin/category/add.blade.php @@ -0,0 +1,7 @@ +@extends('layout.admin', ['title' => 'Админка - Добавление категории']) + +@section('content') +
+ @include('admin.category.form') +
+@endsection diff --git a/resources/views/admin/category/edit.blade.php b/resources/views/admin/category/edit.blade.php new file mode 100644 index 0000000..c4c00a0 --- /dev/null +++ b/resources/views/admin/category/edit.blade.php @@ -0,0 +1,7 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование категории']) + +@section('content') +
+ @include('admin.category.form') +
+@endsection diff --git a/resources/views/admin/category/form.blade.php b/resources/views/admin/category/form.blade.php new file mode 100644 index 0000000..ebd0eef --- /dev/null +++ b/resources/views/admin/category/form.blade.php @@ -0,0 +1,28 @@ +@csrf + +@isset($category) + @method('PUT') +@endisset + +
+
+ +
+
+ +
+
+
diff --git a/resources/views/admin/category/index.blade.php b/resources/views/admin/category/index.blade.php new file mode 100644 index 0000000..a4cb91c --- /dev/null +++ b/resources/views/admin/category/index.blade.php @@ -0,0 +1,91 @@ +@extends('layout.admin', ['title' => 'Админка - Категории']) + +@section('script') + +@endsection + +@section('content') + + + Добавить категорию + +
+
+ +
+ + + + + + + + + + + @foreach($category as $cat) + + + + + + + @endforeach + +
Название категорииДата созданияРедактировать
+ {{$cat->id}} + + {{$cat->name}} + + {{$cat->created_at}} + +
+ Изменить | + @csrf + @method('DELETE') + +
+
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> +
+
+@endsection diff --git a/resources/views/admin/employer/edit.blade.php b/resources/views/admin/employer/edit.blade.php index d9305b2..0504525 100644 --- a/resources/views/admin/employer/edit.blade.php +++ b/resources/views/admin/employer/edit.blade.php @@ -4,16 +4,16 @@

Работодатель-пользователь: "{{$employer->users->name_man}} ({{$employer->user_id}})"

-
+ @csrf

+ +
+ + +
+
+ Флот +
+
+ Вакансии +
+
+ Контакты +
diff --git a/resources/views/admin/worker/edit.blade.php b/resources/views/admin/worker/edit.blade.php index e69de29..1c7e461 100644 --- a/resources/views/admin/worker/edit.blade.php +++ b/resources/views/admin/worker/edit.blade.php @@ -0,0 +1,347 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование соискателя']) + +@section('content') +

+ Соискатель-пользователь: "{{$worker->users->name_man}} ({{$worker->user_id}})" +

+
+ @csrf +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ + + + +
+
+ +
+
+
+
+ + + + + + + + + +@endsection diff --git a/resources/views/layout/admin.blade.php b/resources/views/layout/admin.blade.php index c291e05..2bbcf6b 100644 --- a/resources/views/layout/admin.blade.php +++ b/resources/views/layout/admin.blade.php @@ -154,7 +154,7 @@
  • name('employer-profile'); + // кабинет профиль работодатель - сохранение формы + Route::post('employer-profile/{employer}', [EmployersController::class, 'update_employer'])->name('update-employer-profile'); + // кабинет профиль работник - форма Route::post('worker-profile/{worker}', [WorkersController::class, 'form_update_worker'])->name('worker-profile'); @@ -117,7 +121,12 @@ Route::group([ Route::get('ad-employers', [AdminController::class, 'index'])->name('ad-employers'); // кабинет - категории - Route::get('categories', [AdminController::class, 'index'])->name('categories'); + //Route::get('categories', [AdminController::class, 'index'])->name('categories'); + /* + * CRUD-операции над настройками Компании + */ + Route::resource('categories', CategoryController::class, ['except' => ['show']]); + // кабинет - должности Route::get('job-titles', [AdminController::class, 'index'])->name('job-titles');