app/Http/Controllers/ProductsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        if(auth()->user()->isAdmin()){
            $this->validate($request,[
                'prod_code'=>'required',
                'prod_name'=>'required',
                'prod_unit'=>'required',
                'prod_currency'=>'required',
                'prod_price'=>'required'
            ]);
            $product = Product::find($id);
            if($product === null) abort(404);
            $product->code = $request->input('prod_code');
            $product->name = $request->input('prod_name');
            $product->unit = $request->input('prod_unit');
            $product->price = $request->input('prod_price');
            $product->currency = $request->input('prod_currency');
            $product->subcategory_id = $request->input('prod_subcategory');
            $product->save();
            return redirect('subcategories/'.$product->subcategory_id);
        }
        else abort(404);
    }
public function update ( Request $ request , $ id ) { if ( auth ( ) -> user ( ) -> isAdmin ( ) ) { $ this -> validate ( $ request , [ 'prod_code' => 'required' , 'prod_name' => 'required' , 'prod_unit' => 'required' , 'prod_currency' => 'required' , 'prod_price' => 'required' ] ) ; $ product = Product :: find ( $ id ) ; if ( $ product === null ) abort ( 404 ) ; $ product -> code = $ request -> input ( 'prod_code' ) ; $ product -> name = $ request -> input ( 'prod_name' ) ; $ product -> unit = $ request -> input ( 'prod_unit' ) ; $ product -> price = $ request -> input ( 'prod_price' ) ; $ product -> currency = $ request -> input ( 'prod_currency' ) ; $ product -> subcategory_id = $ request -> input ( 'prod_subcategory' ) ; $ product -> save ( ) ; return redirect ( 'subcategories/' . $ product -> subcategory_id ) ; } else abort ( 404 ) ; }
Update the specified resource in storage.
Update the specified resource in storage .