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)
    {
        $validated = $request->all([
            'title' => 'required',
            'quantity' => 'required',
            'price' => 'required',
            'description' => 'required',
            'image' => 'required'
        ]);
        $product = new Product;
        if($request->hasFile('image'))
        {
            $file = $request->file('image');
            $image = $request->image;
            $imageName = time().'.'.$image->getClientOriginalExtension();
            $file->move('product',$imageName);
        }
        $product->image = $imageName;
        $product->title = $request->title;
        $product->description = $request->description;
        $product->price = $request->price;
        $product->quantity = $request->quantity;
        $product->save();
        return redirect()->back()->with('stutus','Product create successfully');
    }
public function store ( Request $ request ) { $ validated = $ request -> all ( [ 'title' => 'required' , 'quantity' => 'required' , 'price' => 'required' , 'description' => 'required' , 'image' => 'required' ] ) ; $ product = new Product ; if ( $ request -> hasFile ( 'image' ) ) { $ file = $ request -> file ( 'image' ) ; $ image = $ request -> image ; $ imageName = time ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; $ file -> move ( 'product' , $ imageName ) ; } $ product -> image = $ imageName ; $ product -> title = $ request -> title ; $ product -> description = $ request -> description ; $ product -> price = $ request -> price ; $ product -> quantity = $ request -> quantity ; $ product -> save ( ) ; return redirect ( ) -> back ( ) -> with ( 'stutus' , 'Product create successfully' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//