app/Http/Controllers/AgreementPriceBreakController.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)
    {
        $input = $request->all();
		$rules = array ();
		$message = [];
		$validator = Validator::make($input, $rules, $message);
		if($validator->fails()) 
		{
			return back()->withErrors($validator);
		} 
		else 
		{
			$agreementID = $request->input('agreementID', []);
            $revision = $request->input('revision', []);
            $itemID = $request->input('itemID', []);
            $priceBreak = $request->input('priceBreak', []);
            $discount = $request->input('discount', []);                
            for ($item=0; $item < count($itemID); $item++) {
            	$checkVaild = DB::table('agreement_price_break')->where('agreementID', $agreementID[$item])
                												->where('revision', $revision[$item])
            													->where('itemID', $itemID[$item])
            													->get();
            	foreach($checkVaild as $key => $value){
            		 if($priceBreak[$item] == $value->priceBreak){
	                	return back()->withErrors('The price break is already set');
	                }
            	}	
                $agreementPriceBreak = new AgreementPriceBreak;
                if ($itemID[$item] != '') {
                	$agreementPriceBreak->agreementID = $agreementID[$item];
                    $agreementPriceBreak->revision = $revision[$item];
                    $agreementPriceBreak->itemID = $itemID[$item];
                    $agreementPriceBreak->priceBreak =$priceBreak[$item];
                    $agreementPriceBreak->discount =$discount[$item];
                    $agreementPriceBreak->save();
                }
            }
            return back()->with('success','Agreement Price Break Information Saved Sucessfully');
		}
    }
public function store ( Request $ request ) { $ input = $ request -> all ( ) ; $ rules = array ( ) ; $ message = [ ] ; $ validator = Validator :: make ( $ input , $ rules , $ message ) ; if ( $ validator -> fails ( ) ) { return back ( ) -> withErrors ( $ validator ) ; } else { $ agreementID = $ request -> input ( 'agreementID' , [ ] ) ; $ revision = $ request -> input ( 'revision' , [ ] ) ; $ itemID = $ request -> input ( 'itemID' , [ ] ) ; $ priceBreak = $ request -> input ( 'priceBreak' , [ ] ) ; $ discount = $ request -> input ( 'discount' , [ ] ) ; for ( $ item = 0 ; $ item < count ( $ itemID ) ; $ item ++ ) { $ checkVaild = DB :: table ( 'agreement_price_break' ) -> where ( 'agreementID' , $ agreementID [ $ item ] ) -> where ( 'revision' , $ revision [ $ item ] ) -> where ( 'itemID' , $ itemID [ $ item ] ) -> get ( ) ; foreach ( $ checkVaild as $ key => $ value ) { if ( $ priceBreak [ $ item ] == $ value -> priceBreak ) { return back ( ) -> withErrors ( 'The price break is already set' ) ; } } $ agreementPriceBreak = new AgreementPriceBreak ; if ( $ itemID [ $ item ] != '' ) { $ agreementPriceBreak -> agreementID = $ agreementID [ $ item ] ; $ agreementPriceBreak -> revision = $ revision [ $ item ] ; $ agreementPriceBreak -> itemID = $ itemID [ $ item ] ; $ agreementPriceBreak -> priceBreak = $ priceBreak [ $ item ] ; $ agreementPriceBreak -> discount = $ discount [ $ item ] ; $ agreementPriceBreak -> save ( ) ; } } return back ( ) -> with ( 'success' , 'Agreement Price Break Information Saved Sucessfully' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .