app/Http/Controllers/ItemController.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)
    {
        $input = $request->all();                  
 		$rules = array ('virtualItemID' => 'required',
						'name' => 'required',
						'unitOfMeasurement' => 'required',
						'categoryID' => 'required',);
		$messages = ['name.required' => 'Please input the item name',
					'virtualItemID.required' => 'Please input the virtual item number',
					'unitOfMeasurement.required' => 'Please input the unit of Measurement',
					'categoryID.required' => 'Please select the correct category ',
					'categoryID.numeric' => 'Please input the Category number in correct format',];
        $validator = Validator::make($input, $rules, $messages);        
        if ($validator->fails()) {             
            return Redirect::to('item/edit')->withErrors($validator);        
        } else if (!$this->foreignKeyExists($request)) {
            return back()->withErrors('Failed to edit the Item as categoryID is not found on ItemCategory Table !'); 
        }else {       
            $item = Item::find($id);    
            $item->name = $request->name;
			$item->virtualItemID = $request->virtualItemID;
			$item->unitOfMeasurement = $request->unitOfMeasurement;
			$item->description = $request->description;
			$item->categoryID = $request->categoryID;
        	$item->save();
            return Redirect::to('item')->with('success','Successfully updated Item !');     
        } 
    }
public function update ( Request $ request , $ id ) { $ input = $ request -> all ( ) ; $ rules = array ( 'virtualItemID' => 'required' , 'name' => 'required' , 'unitOfMeasurement' => 'required' , 'categoryID' => 'required' , ) ; $ messages = [ 'name.required' => 'Please input the item name' , 'virtualItemID.required' => 'Please input the virtual item number' , 'unitOfMeasurement.required' => 'Please input the unit of Measurement' , 'categoryID.required' => 'Please select the correct category ' , 'categoryID.numeric' => 'Please input the Category number in correct format' , ] ; $ validator = Validator :: make ( $ input , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return Redirect :: to ( 'item/edit' ) -> withErrors ( $ validator ) ; } else if ( ! $ this -> foreignKeyExists ( $ request ) ) { return back ( ) -> withErrors ( 'Failed to edit the Item as categoryID is not found on ItemCategory Table !' ) ; } else { $ item = Item :: find ( $ id ) ; $ item -> name = $ request -> name ; $ item -> virtualItemID = $ request -> virtualItemID ; $ item -> unitOfMeasurement = $ request -> unitOfMeasurement ; $ item -> description = $ request -> description ; $ item -> categoryID = $ request -> categoryID ; $ item -> save ( ) ; return Redirect :: to ( 'item' ) -> with ( 'success' , 'Successfully updated Item !' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .