コード例 #1
0
 public function update($id, Request $request)
 {
     $validator = Validator::make($request->all(), ['firstname' => 'required|max:255', 'lastname' => 'required|max:255']);
     if ($validator->fails()) {
         return Redirect::to('/admin/user/' . $id)->withErrors($validator);
     }
     $user = User::find($id);
     $user->firstname = $request->firstname;
     $user->middlename = $request->middlename;
     $user->lastname = $request->lastname;
     if ($user->type == 'student') {
         $user->year_level = $request->year_level;
     } else {
         $user->position = $request->position;
         $user->department_id = $request->department;
     }
     $user->gender = $request->gender;
     $user->birthdate = $request->birthdate;
     $user->address = $request->address;
     $user->contact = $request->contact;
     $user->save();
     if ($user->type == 'student') {
         if (count($user->section)) {
             $section = $user->section;
         } else {
             $section = new StudentSection();
             $section->user_id = $user->id;
         }
         $section->section_id = $request->section;
         $section->save();
     }
     return Redirect::to('/admin/user/' . $id);
 }
コード例 #2
0
 public function storeAccount(Request $request)
 {
     $validator = Validator::make($request->all(), ['username' => 'required|unique:users', 'password' => 'required|min:6', 'firstname' => 'required|max:255', 'lastname' => 'required|max:255']);
     if ($validator->fails()) {
         return Redirect::to('/admin/account/create')->withInput()->withErrors($validator);
     }
     $user = new User();
     $user->username = $request->username;
     $user->password = bcrypt($request->password);
     $user->type = $request->type;
     $user->firstname = $request->firstname;
     $user->middlename = $request->middlename;
     $user->lastname = $request->lastname;
     if ($request->type == 'student') {
         $user->year_level = $request->yearlevel;
     } else {
         $user->position = $request->position;
         $user->department_id = $request->department;
     }
     $user->gender = $request->gender;
     $user->birthdate = $request->birthdate;
     $user->address = $request->address;
     $user->contact = $request->contact;
     $user->save();
     if ($user->type == 'student') {
         StudentSection::firstOrCreate(['user_id' => $user->id, 'section_id' => $request->section]);
     }
     $temporaryPassword = new TemporaryPassword();
     $temporaryPassword->user_id = $user->id;
     $temporaryPassword->password = $request->password;
     $temporaryPassword->save();
     return Redirect::to('/admin/account/create')->with('status', 'Account created successfully.');
 }