app/Http/Controllers/ItemController.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 ('virtualItemID' => 'required',
						'name' => 'required',
						'unitOfMeasurement' => 'required',
						'categoryID' => 'required',);
		$messages = ['name.required' => 'Please input the item name',
					 'virtualItemID.required' => 'Please input the virtual item ID',
					 'unitOfMeasurement.required' => 'Please input the unit of Measurement',
					 'virtualItemID.numeric' => 'Please input the Virtual Item ID number in correct format',
					 'categoryID.required' => 'Please select the correct category',];
		$validator = Validator::make($input, $rules, $messages);
		if($validator->fails()) {
			return Redirect::to('item/create')->withErrors($validator);
		}else if(!$this->foreignKeyExists($request)) {
		    return back()->withErrors('Failed to store Items as categoryID does not exist on ItemCategory Table'); 
		}else {
			$item = new Item;
			$item->name = $request->name;
			$item->virtualItemID = $request->virtualItemID;
			$item->unitOfMeasurement = $request->unitOfMeasurement;
			$item->description = $request->description;
			$item->categoryID = $request->categoryID;
			$item->save();
			return redirect('item')->with('success','Create Item Successfully');
		}
    }
public function store ( Request $ request ) { $ 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 ID' , 'unitOfMeasurement.required' => 'Please input the unit of Measurement' , 'virtualItemID.numeric' => 'Please input the Virtual Item ID number in correct format' , 'categoryID.required' => 'Please select the correct category' , ] ; $ validator = Validator :: make ( $ input , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return Redirect :: to ( 'item/create' ) -> withErrors ( $ validator ) ; } else if ( ! $ this -> foreignKeyExists ( $ request ) ) { return back ( ) -> withErrors ( 'Failed to store Items as categoryID does not exist on ItemCategory Table' ) ; } else { $ item = new Item ; $ item -> name = $ request -> name ; $ item -> virtualItemID = $ request -> virtualItemID ; $ item -> unitOfMeasurement = $ request -> unitOfMeasurement ; $ item -> description = $ request -> description ; $ item -> categoryID = $ request -> categoryID ; $ item -> save ( ) ; return redirect ( 'item' ) -> with ( 'success' , 'Create Item Successfully' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .