Again and again..
Explain me the code below:
Slider::where('id',$slider->id)
You defined $validatedData['image'] inside the if, so what do you think will happen if you don't upload the image?
Hello, I have a problem with my laravel project (I'm quite new to Laravel). So I'm creating an e-commerce website and everything was fine until i decided to update my slider data and image to my slider. Now when I am submitting my form i have an error: Undefined array key "image".
public function update(SliderFormRequest $request, Slider $slider) { $validatedData = $request->validated();
if($request->hasFile('image')){
$destination = $slider->image;
if(File::exists($destination)){
File::delete($destination);
}
$file = $request->file('image');
$ext = $file->getClientOriginalExtension();
$filename = time().'.'.$ext;
$file->move('uploads/slider/', $filename);
$validatedData['image'] = "uploads/slider/$filename";
}
$validatedData['status'] = $request->status == true ? '1':'0';
Slider::where('id',$slider->id)->update([
'title' => $validatedData['title'],
'description' => $validatedData['description'],
'image' => $validatedData['image'],
'status' => $validatedData['status'],
]);
return redirect('admin/sliders')->with('message', 'Slider Added Successfully!');
}
it show error while updating image 'image' => $validatedData['image'],
Please or to participate in this conversation.