get(); return view('admin.sliders.index', compact('sliders')); } public function create() { return view('admin.sliders.create'); } public function store(SliderRequest $request): RedirectResponse { $data = $request->validated(); if ($request->hasFile('image')) { $data['image'] = $this->fileUpload($request->file('image')); } Slider::create($data); return redirect()->route('admin.sliders.index')->with('success', 'Слайдер создан успешно !'); } public function show($id) { // } public function edit(Slider $slider) { return view('admin.sliders.edit', compact('slider')); } public function update(Request $request, Slider $slider) { $data = $request->all(); if ($request->hasFile('image')) { $data['image'] = $this->fileUpload($request->file('image')); } $slider->update($data); return redirect()->route('admin.sliders.index')->with('success', 'Слайдер обновлен успешно !'); } public function destroy(Slider $slider) { $slider->delete(); return redirect()->route('admin.sliders.index')->with('success', 'Слайдер удален успешно !'); } public function fileUpload($file) { $filename = time().'_'.$file->getClientOriginalName(); $file->move(public_path(Slider::FILE_PATH), $filename); return $filename; } }