[php] Laravel 4 with Sentry 2 add user to a group on Registration

So, I'm trying to implement Sentry 2 with Laravel 4.1. I'm using this resource for it

https://github.com/rydurham/L4withSentry

Everything works fine, but now I want to assign user to a group automatically when he registers.

From Sentry 2 Docs,

    // Find the group using the group id     $adminGroup = Sentry::findGroupById(5);      // Assign the group to the user     $user->addGroup($adminGroup); 

Should work. So I added this lines of code to Authority\Repo\User\SentryUser.php

Now the code looks like

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']); } 

But this throws in an error

Non-static method Cartalyst\Sentry\Sentry::findGroupById() should not be called statically, assuming $this from incompatible context  

Can anyone shed a light and tell me what I'm doing wrong? Thanks in Advance

This question is related to php laravel laravel-4 cartalyst-sentry

The answer is


Somehow, where you are using Sentry, you're not using its Facade, but the class itself. When you call a class through a Facade you're not really using statics, it's just looks like you are.

Do you have this:

use Cartalyst\Sentry\Sentry; 

In your code?

Ok, but if this line is working for you:

$user = $this->sentry->register(array(     'username' => e($data['username']),     'email' => e($data['email']),      'password' => e($data['password'])     )); 

So you already have it instantiated and you can surely do:

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

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-4

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration 'Malformed UTF-8 characters, possibly incorrectly encoded' in Laravel Can I do Model->where('id', ARRAY) multiple where conditions? how to fix stream_socket_enable_crypto(): SSL operation failed with code 1 Rollback one specific migration in Laravel How can I resolve "Your requirements could not be resolved to an installable set of packages" error? Define the selected option with the old input in Laravel / Blade Redirect to external URL with return in laravel laravel the requested url was not found on this server

Examples related to cartalyst-sentry

Laravel 4 with Sentry 2 add user to a group on Registration