private function registerStaff($staff_id, $name) { if (StaffInfo::where('staff_id', '=', $staff_id)->count() > 0) { return true; } else { $staff = new StaffInfo(); $staff->staff_id = $staff_id; $staff->surname = $name; $staff->created_by = Auth::user()->get_user_id(); $staff->updated_by = Auth::user()->get_user_id(); $staff->approved_by = Auth::user()->get_user_id(); $staff->created_at = date("Y-m-d"); $staff->status = 0; if ($staff->save()) { return true; } else { return false; } } }
public function updateStaff() { $rules = array('staffid' => 'required', 'surname' => 'required', 'othernames' => 'required', 'gender' => 'required', 'birthdate' => 'required', 'mobile' => 'required', 'designation' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { $staff = StaffInfo::where('staff_id', '=', Input::get('staffid'))->first(); return View::make('Staff.newStaff')->with('staff', $staff)->with('designations', Designations::all())->with('form_error_message', $validation->errors()->first()); } else { $dob = new DateTime(Input::get('birthdate')); $affectedRows = StaffInfo::where('staff_id', '=', Input::get('staffid'))->update(array('designation_id' => Input::get('designation'), 'surname' => Input::get('surname'), 'other_names' => Input::get('othernames'), 'gender' => Input::get('gender'), 'date_of_birth' => date_format($dob, 'Y-m-d'), 'contact_no' => Input::get('mobile'), 'email' => Input::get('email'), 'postal_address' => Input::get('postaladdress'), 'residential_address' => Input::get('residentialaddress'), 'ssn' => Input::get('ssn'), 'nok_name' => Input::get('nokname'), 'nok_contact' => Input::get('nokcontact'), 'nok_address' => Input::get('nok_address'), 'updated_by' => Auth::user()->get_user_id(), 'updated_at' => date('Y-m-d'), 'status' => 1)); if ($affectedRows > 0) { $staff = StaffInfo::where('staff_id', '=', Input::get('staffid'))->first(); return View::make('Staff.newStaff')->with('staff', $staff)->with('designations', Designations::all())->with('success_message', 'Update complete.'); } else { $staff = StaffInfo::where('staff_id', '=', Input::get('staffid'))->first(); return View::make('Staff.newStaff')->with('staff', $staff)->with('designations', Designations::all())->with('form_error_message', 'An error occured while updating staff infomation.'); } } }