'error (Call to a member function getClientOriginalName() on null )

class Products extends Controller
{
    public function index()
{
        $products = DB::table('product')->get();
        return view("product", compact('products'));
}
    public function store(Request $request)
{
            $file = $request->file('image');
        if ($request->hasFile('image')) {
            $name = $file->getClientOriginalName();
            $extension = $file->getClientOriginalExtension();
            $path =  $file->store(public_path('image'));
            $request->image->move($path, $extension);
 }
        DB::table('product')->insert([
            'name' => $request->name,
            'price' => $request->price,
            'photo' => $name
]);
}
}

strong text// //i make correct route and make sure from form inputs and enctype="multipart/form-data" but i have error when use my method store i see error Call to a member function getClientOriginalName() on null and dd{$file} return null



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source