I am trying to update image to image/brand/ folder but unexpectedly error is occurred.
public function update(Request $request,$id){
$validated = $request->validate([
'brand_name' => 'required|max:4',
// 'brand_image' => 'required|mimes:jpg,jpeg,png',
]);
$old_image=$request->old_image;
$brandimage=$request->file('brand_image');
$image_gen=hexdec(uniqid());
$image_exten=strtolower($brandimage->getClientOriginalExtension());
$image_name=$image_gen.'.'.$image_exten;
$image_location='image/brand/';
$image_uplioad= $image_location.$image_name;
$brandimage->move($image_location,$image_name);
unlink($old_image);
Brand::find($id)->update([
'brand_name' =>$request->brand_name,
'brand_image'=>$image_uplioad,
'Created_at'=> Carbon::Now()
]);
return Redirect()->back()->with('success','Brand image updated Successfully');
}
ErrorException
unlink(): Invalid argument this is the error what i got i need over come this problem please help
2
Answers
You could optimize it by update the image from model by creating
updateImage
method inside the model like thisBrand Model
after that the controller will be like this
please pass the
$old_image=$request->old_image;
value from in blade.