【发布时间】:2014-05-18 14:34:46
【问题描述】:
我为我的 Laravel 应用创建了一个自定义 Auth 驱动程序。现在我想知道向我的身份验证会话添加额外数据的标准方法是什么。
我创建了一个自定义守卫:
class MyAppGuard extends Guard {
//...
}
用户提供者:
class MyAppUserProvider implements UserProviderInterface {
//...
}
我已经在global.php注册了我的驱动程序:
Auth::extend('mydriver', function($app) {
$provider = new \MyApp\Auth\MyAppUserProvider($app['hash'], 'User');
return new \MyApp\Auth\MyAppGuard($provider, $app['session.store']);
});
一切似乎都正常,我可以调用MyAppGuard 的自定义方法和Auth::myCustomMethod() 等等。
我现在想将用户的所有权限添加到会话中,以便可以通过Auth::permissions() 访问它们,就像用户通过Auth::user() 一样。
我应该怎么做,我确信我可以用一些丑陋的方式来做,但必须有一个最佳实践?
【问题讨论】:
-
你是如何检查 API 的?