public function update($username, Request $request)
{
$user = $this->getUserByUsername($username);
$input = Input::only('location', 'bio', 'twitter_username', 'github_username');
$profile_validator = $this->profile_validator($request->all());
if ($profile_validator->fails()) {
$this->throwValidationException($request, $profile_validator);
return redirect('profile/' . $user->name . '/edit')->withErrors($validator)->withInput();
}
if ($user->profile == null) {
$profile = new Profile();
$profile->fill($input);
$user->profile()->save($profile);
} else {
$user->profile->fill($input)->save();
}
return redirect('profile/' . $user->name . '/edit')->with('status', 'Profile updated!');
}