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)
    {
        $arrWithPartsId = [];
        foreach($request->input('partquantity') as $item)
        {
            $arrWithPartsId['item'] = [
                'id' => $request->input('id'),
                'quantity' => $request->input('partquantity')
            ];
        }
        $product = new Products();
        $product->name = $request->input('name');
        $product->price = $request->input('price');
        $product->notes = $request->input('inputText');
        if ($image = $request->file('image')) {
            $destinationPath = 'image/';
            $profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
            $image->move($destinationPath, $profileImage);
            $product->image = "$profileImage";
        }
        $product->parts = json_encode($arrWithPartsId);
        $product->save();
        return redirect('/products/create')->with('success', 'Game is successfully saved');
    }
public function store ( Request $ request ) { $ arrWithPartsId = [ ] ; foreach ( $ request -> input ( 'partquantity' ) as $ item ) { $ arrWithPartsId [ 'item' ] = [ 'id' => $ request -> input ( 'id' ) , 'quantity' => $ request -> input ( 'partquantity' ) ] ; } $ product = new Products ( ) ; $ product -> name = $ request -> input ( 'name' ) ; $ product -> price = $ request -> input ( 'price' ) ; $ product -> notes = $ request -> input ( 'inputText' ) ; if ( $ image = $ request -> file ( 'image' ) ) { $ destinationPath = 'image/' ; $ profileImage = date ( 'YmdHis' ) . " . " . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( $ destinationPath , $ profileImage ) ; $ product -> image = " $ profileImage " ; } $ product -> parts = json_encode ( $ arrWithPartsId ) ; $ product -> save ( ) ; return redirect ( '/products/create' ) -> with ( 'success' , 'Game is successfully saved' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .