Php Laravel 4和Sentry 2在注册时将用户添加到组

Php Laravel 4和Sentry 2在注册时将用户添加到组,php,laravel,laravel-4,cartalyst-sentry,Php,Laravel,Laravel 4,Cartalyst Sentry,所以,我试图用Laravel 4.1实现哨兵2。我正在使用这个资源 一切正常,但现在我想在用户注册时自动将其分配到一个组 来自哨兵2号文件 // Find the group using the group id $adminGroup = Sentry::findGroupById(5); // Assign the group to the user $user->addGroup($adminGroup); 应该有用。因此,我将这行代码添加到 A

所以,我试图用Laravel 4.1实现哨兵2。我正在使用这个资源

一切正常,但现在我想在用户注册时自动将其分配到一个组

来自哨兵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 
谁能告诉我我做错了什么?
提前感谢

不知何故,当您使用Sentry时,您使用的不是它的外观,而是类本身。当你通过一个门面调用一个类时,你并没有真正使用静态,只是看起来你是这样

你有这个吗:

use Cartalyst\Sentry\Sentry;
在你的代码里

好的,但是如果这一行适合你:

$user = $this->sentry->register(array(
    'username' => e($data['username']),
    'email' => e($data['email']), 
    'password' => e($data['password'])
    ));
因此,您已经对其进行了实例化,并且您肯定可以执行以下操作:

$adminGroup = $this->sentry->findGroupById(5);

非常感谢安东尼奥!!答案在理论上是如此正确,以至于我在申请之前就知道它会起作用:)而且它确实起作用了!荣誉