Php Can';t访问雄辩的静态方法(在Laravel之外使用)

Php Can';t访问雄辩的静态方法(在Laravel之外使用),php,methods,orm,static,eloquent,Php,Methods,Orm,Static,Eloquent,我遵循了杰弗里·韦的解释和其他几篇博客文章,但仍然无法实现这一点 我想在拉拉维尔之外使用雄辩的ORM。我已经在我的composer.json中包含了这些需求: "illuminate/database": "v5.*", "illuminate/events": "v5.*", 然后我实例化了胶囊管理器: $db = new Illuminate\Database\Capsule\Manager(); $db->addConnection($config['database']); $d

我遵循了杰弗里·韦的解释和其他几篇博客文章,但仍然无法实现这一点

我想在拉拉维尔之外使用雄辩的ORM。我已经在我的
composer.json中包含了这些需求:

"illuminate/database": "v5.*",
"illuminate/events": "v5.*",
然后我实例化了胶囊管理器:

$db = new Illuminate\Database\Capsule\Manager();
$db->addConnection($config['database']);
$db->setEventDispatcher(new Illuminate\Events\Dispatcher(new Illuminate\Container\Container));
$db->setAsGlobal();
$db->bootEloquent();
我构建了一个基本的用户模型,扩展了雄辩的模型:

use Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent
{
    public $incrementing = false;
    protected $primaryKey = 'username';
    protected $keyType = 'string';
}
现在,我可以按预期创建一个新用户:

$u = new User([
    'username' => $username,
    'fullname' => $fullname,
    'role_id'  => $role_id,
]);
$u->save();
这就像一个符咒,用户出现在预定的
users
表中,但我无法通过这些方法检索用户,我的响应总是
null

$user = User::find('foo'); // no dice
$user = User::where('username', 'foo')->get(); // nope
$user = User::first(); // nothing
有人知道为什么我不能使用雄辩的模型附带的静态方法吗?或者更好的是,如何解决这个问题