1

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

?>
4

2 回答 2

2

Sentry::getUserProvider()应该从运行实例的控制器调用。

如果要扩展Sentry\User模型,请像这样创建模型:

class User extends Cartalyst\Sentry\Users\Eloquent\User { ... }
于 2013-08-15T14:15:45.150 回答
0

对于您的问题,我的回答很可能为时已晚,但它可能对其他开发人员有所帮助。

答:只需编辑您的命名空间。

更改:使用 Cartalyst\Sentry\Sentry;

To :使用 Sentry ;

于 2013-09-11T22:44:03.030 回答