public function allocateServiceSave() { // validate the info, create rules for the inputs $rules = array(); $i = 1; $count = PetTypes::all()->count(); // run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules); // if the validator fails, redirect back to the form if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('allocate_service/list')->with('flash_error', $messages->first()); } else { for ($i = 1; $i <= $count; $i++) { $i_allocate_id = Input::get('hdn-allocate-id-' . $i); $i_service_type_id = Input::get('hdn-service-type-' . $i); $a_pet_types = Input::get('slt-pet-types-' . $i); //echo "<pre>"; print_r($a_pet_types); die; if (is_array($a_pet_types)) { $s_pet_types_ids = implode(",", $a_pet_types); if ($i_allocate_id == 0) { $allocate_service = new AllocateServices(); } else { $allocate_service = AllocateServices::find($i_allocate_id); } $allocate_service->service_type_id = $i_service_type_id; $allocate_service->pet_type_ids = $s_pet_types_ids; $allocate_service->save(); } } // validation not successful, send back to form return Redirect::to('allocate_service/list')->with('flash_success', 'Allocate services successfully saved.'); } }