In this tutorial i’m going to learn how to solve this issue Call to a member function getClientOriginalExtension() on null.
This error usually occurs when you try to call getClientOriginalExtension()
on a null value. This can happen when you’re trying to access the file extension of an uploaded file, but the file may not have been successfully uploaded or the file input might be empty.
Error:-
Call to a member function getClientOriginalExtension() on null
Solution :-
$name_gen = strtolower($image->getClientOriginalExtension());
Full code :-
public function UpdateProductThambnail(Request $request){
Log::info("id me kya aa rha hai".$request->id);
$pro_id = $request->id;
$oldImage = $request->old_img;
$image = $request->product_thambnail;
$name_gen = strtolower($image->getClientOriginalExtension());
Image::make($image)->resize(800,800)->save('upload/products/thambnail/'.$name_gen);
$save_url = 'upload/products/thambnail/'.$name_gen;
if (file_exists($oldImage)) {
unlink($oldImage);
}
Product::findOrFail($pro_id)->update([
'product_thambnail' => $save_url,
'updated_at' => Carbon::now(),
]);
$notification = array(
'message' => 'Product Image Thambnail Updated Successfully',
'alert-type' => 'success'
);
return redirect()->back()->with($notification);
}