我对Sentry有问题。问题可能是在$ user = Sentry :: getUserProvider() - > findById($ id)下;它不仅找到一个用户,而且找到很多用户。因此,它无法识别方法user-> save。
我该如何解决这个问题?
我正在尝试构建一个表单来编辑我的用户详细信息。
谢谢。
我的表单如下:
{{ Form::open(array('url' => 'profile/useredit')) }}
{{ Form::text('address',null) }}
<br>
{{Form::submit('Submit', array('class' => 'btn btn-default'))}}
{{ Form::close() }}
/**
* Edit the user profile under profile/user
*
* @return View
*/
public function postUseredit(){
try {
$id= Session::get(Config::get('sentry::sentry.session.user'));
// Get the user information
$user = Sentry::getUserProvider()->findById($id);
} catch (UserNotFoundException $e) {
// Prepare the error message
$error = Lang::get('users/message.user_not_found', compact('id'));
// Redirect to the user management page
return Redirect::route('users')->with('error', $error);
}
try {
// Update the user
$user->first_name = Input::get('first_name');
$user->last_name = Input::get('last_name');
$user->email = Input::get('email');
$user->dob = Input::get('dob');
$user->bio = Input::get('bio');
$user->gender = Input::get('gender');
$user->country = Input::get('country');
$user->state = Input::get('state');
$user->city = Input::get('city');
$user->address = Input::get('address');
$user->postal = Input::get('postal');
$user->activated = Input::get('activate')?1:0;
/*
// is new image uploaded?
if ($file = Input::file('pic'))
{
$fileName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension() ?: 'png';
$folderName = '/uploads/users/';
$destinationPath = public_path() . $folderName;
$safeName = str_random(10).'.'.$extension;
$file->move($destinationPath, $safeName);
//delete old pic if exists
if(File::exists(public_path() . $folderName.$user->pic))
{
File::delete(public_path() . $folderName.$user->pic);
}
//save new file path into db
$user->pic = $safeName;
}
*/
/*
// Get the current user groups
$userGroups = $user->groups()->lists('group_id', 'group_id');
// Get the selected groups
$selectedGroups = Input::get('groups', array());
// Groups comparison between the groups the user currently
// have and the groups the user wish to have.
$groupsToAdd = array_diff($selectedGroups, $userGroups);
$groupsToRemove = array_diff($userGroups, $selectedGroups);
// Assign the user to groups
foreach ($groupsToAdd as $groupId) {
$group = Sentry::getGroupProvider()->findById($groupId);
$user->addGroup($group);
}
// Remove the user from groups
foreach ($groupsToRemove as $groupId) {
$group = Sentry::getGroupProvider()->findById($groupId);
$user->removeGroup($group);
}
*/
// Was the user updated?
if ($user->save()) {
// Prepare the success message
$success = Lang::get('users/message.success.update');
// Redirect to the user page
return Redirect::route('profile/user', $id)->with('success', $success);
}
// Prepare the error message
$error = Lang::get('users/message.error.update');
} catch (LoginRequiredException $e) {
$error = Lang::get('users/message.user_login_required');
}
// Redirect to the user page
return Redirect::route('profile/user', $id)->withInput()->with('error', $error);
}
答案 0 :(得分:0)
而不是
$user = Sentry::getUserProvider()->findById($id);
试试这个
$user = Sentry::findUserById($id);