И така, опитвам се да внедря Sentry 2 с Laravel 4.1. Използвам този ресурс за това
https://github.com/rydurham/L4withSentry
Всичко работи добре, но сега искам да присвоя потребител към група автоматично, когато се регистрира.
От Sentry 2 Docs,
// 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
Може ли някой да хвърли светлина и да ми каже какво правя погрешно? Благодаря предварително