I'm getting the following error "trying to get a property of a non-object" when I submit a form to add a user, the error is apparently on the first line: Auth::user()->id of the following:
$id = Auth::user()->id;
$currentuser = User::find($id);
$usergroup = $currentuser->user_group;
$group = Sentry::getGroupProvider()->findById($usergroup);
$generatedPassword = $this->_generatePassword(8,8);
$user = Sentry::register(array('email' => $input['email'], 'password' => $generatedPassword, 'user_group' => $usergroup));
$user->addGroup($group);
Any ideas? I've searched for a while and everything I see says this should work fine. My user is logged in using the Sentry 2 authentication bundle.
Auth::user();
? the Auth::user() returns the current logged in user, so you are trying to register a user which should be logged in, it doesn't make sense – AltrimSentry::getUser()->id
. The error you get is that theAuth::user()
returns NULL and it tries to get id from NULL hence the errortrying to get a property from a non-object
. – Altrim