Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     //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") {
         Staff::edit_staff_role($input, $id);
     } 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::edit_admin_role($input, $id);
             } else {
                 return Redirect::back()->withErrors(["Passwords do not match!"]);
             }
         }
         //end if else password is empty for admin
     }
     //end if else for user role
     $staff = Staff::get_staff($id);
     $message = 'Staff "' . $staff->name . '" has been updated successfully.';
     return view('staffs.show', compact('staff', 'message'));
     //return redirect('staffs');
 }