Итак, я пытаюсь реализовать Sentry 2 с Laravel 4.1. Я использую этот ресурс для этого
https://github.com/rydurham/L4withSentry
Все работает нормально, но теперь я хочу автоматически добавлять пользователя в группу, когда он регистрируется.
Из документов Sentry 2,
// Find the group using the group id
$adminGroup = Sentry::findGroupById(5);
// Assign the group to the user
$user->addGroup($adminGroup);
Должно сработать. Поэтому я добавил эти строки кода в Authority\Repo\User\SentryUser.php.
Теперь код выглядит так
try {
//Attempt to register the user.
$user = $this->sentry->register(array(
'username' => e($data['username']),
'email' => e($data['email']),
'password' => e($data['password'])
));
// Find the group using the group id
$adminGroup = Sentry::findGroupById(5);
// Assign the group to the user
$user->addGroup($adminGroup);
//success!
$result['success'] = true;
$result['message'] = trans('users.created');
$result['mailData']['activationCode'] = $user->GetActivationCode();
$result['mailData']['userId'] = $user->getId();
$result['mailData']['email'] = e($data['email']);
}
Но это выдает ошибку
Non-static method Cartalyst\Sentry\Sentry::findGroupById() should not be called statically, assuming $this from incompatible context
Может ли кто-нибудь пролить свет и сказать мне, что я делаю неправильно? Заранее спасибо