Question

I am trying to call Sentry:: from within an Eloquent model. However, I am getting the error

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

Current code is below. What am I doing wrong?

<?php
namespace App\Model;

use Cartalyst\Sentry\Users\Eloquent\User as CartalystUser;
use Cartalyst\Sentry\Sentry;


class User extends CartalystUser {

    protected $table = 'users';

    protected $hidden = array('password');


    public function __construct() {

        $users = Sentry::getUserProvider()->findAll();

        print_r($users);

        exit;
    }

    public function brands() {
        return $this->hasMany('Brand'); 
    }
}

?>
Was it helpful?

Solution

Sentry::getUserProvider() should be called from a controller, where an instance run.

If you want to extend a Sentry\User model, create your model like this :

class User extends Cartalyst\Sentry\Users\Eloquent\User { ... }

OTHER TIPS

My answer is most likely too late for your question , but it might be helpful to other developers .

Answer : Just edit your namespace .

Change : use Cartalyst\Sentry\Sentry;

To : use Sentry ;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top