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.');
 }
 public function store(Request $request)
 {
     $users = User::where('type', '!=', 'admin')->get();
     $passwords = $request->passwords;
     foreach ($users as $i => $user) {
         $temp = TemporaryPassword::firstOrNew(['user_id' => $user->id]);
         $temp->password = $passwords[$i];
         $temp->save();
         $user->password = bcrypt($passwords[$i]);
         $user->save();
     }
 }