/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { //this validate method will validate the input fields before creating it into the database $this->validate($request, ['name' => 'required', 'staff_id' => 'required', 'role' => 'required']); //Store method is responsible for throwing data into database, and redirect to somewhere else $input = $request->all(); if ($input['role'] == "Staff") { //multiple ways to add into the database, this one of them $staff = Staff::create_new_staff($input); } else { //password validation if ($input['password'] == "" || $input['confirm_password'] == "") { return Redirect::back()->withErrors(["The Password/Confirm password field is required."]); } else { if ($input['password'] == $input['confirm_password']) { // If Successful $staff = Staff::create_new_admin($input); } else { return Redirect::back()->withErrors(["Passwords do not match!"]); } } //end if else password is empty for admin } //end if else for user role $message = 'New Staff "' . $staff->name . '" has been created successfully.'; return view('staffs.show', compact('staff', 'message')); }