/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $rules = ['password' => 'confirmed|min:6']; if (Auth::user()->admin) { $rules['username'] = '******'; $rules['institution_id'] = 'integer'; } $this->validate($request, $rules); if (Auth::user()->admin) { $data = Input::only(['username', 'institution_id', 'admin']); $data['admin'] = Input::has('admin') ? true : false; if (empty($data['institution_id'])) { $data['institution_id'] = null; } } $data['password'] = Input::get('password'); if (!empty($data['password'])) { $data['password'] = bcrypt($data['password']); } else { unset($data['password']); } User::find($id)->update($data); return Redirect::route(Auth::user()->admin ? 'users.index' : 'home'); }
public function run() { DB::table('users')->delete(); User::create(array('name' => 'Administrator', 'username' => 'Admin', 'password' => bcrypt('TAEadmin'), 'admin' => true)); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['username' => $data['username'], 'institution_id' => $data['institution_id'], 'password' => bcrypt($data['password'])]); }