app/Http/Controllers/ProductController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        request()->validate([
            'name' => 'required',
            'brand' => 'required',
            'price' => 'required',
            'image' => ['required', 'file', 'mimes:jpeg,bmp,png'],
        ]);
        $product =  Product::create($request->all());
        if ($request->hasFile('image')) {
            $imageName = time().'.'.$request->image->getClientOriginalExtension();
            $request->image->move(public_path('/uploads/product'), $imageName);
            $product->update(['image' => $imageName]);
        }
        return redirect()->route('products.index')
            ->with('success', 'Product created successfully.');
    }
public function store ( Request $ request ) { request ( ) -> validate ( [ 'name' => 'required' , 'brand' => 'required' , 'price' => 'required' , 'image' => [ 'required' , 'file' , 'mimes:jpeg,bmp,png' ] , ] ) ; $ product = Product :: create ( $ request -> all ( ) ) ; if ( $ request -> hasFile ( 'image' ) ) { $ imageName = time ( ) . '.' . $ request -> image -> getClientOriginalExtension ( ) ; $ request -> image -> move ( public_path ( '/uploads/product' ) , $ imageName ) ; $ product -> update ( [ 'image' => $ imageName ] ) ; } return redirect ( ) -> route ( 'products.index' ) -> with ( 'success' , 'Product created successfully.' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// 'detail' => 'required',