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') +
+@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') + +@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 + +№ | +Название категории | +Дата создания | +Редактировать | +
---|---|---|---|
+ {{$cat->id}} + | ++ {{$cat->name}} + | ++ {{$cat->created_at}} + | ++ + | +