【发布时间】:2019-08-24 00:13:24
【问题描述】:
我正在App\Services\Factures 中创建一个名为Factures 的新服务。
我创建了\App\Services\Factures\FacturesServiceProvider:
public function register() {
$this->app->bind('factures', function ($app) {
return new Facture;
});
}
public function boot() {
// laod Routes
$this->loadRoutesFrom(__DIR__ .'/Http/routes.php');
// load Views
$this->loadViewsFrom(__DIR__ . '/views', 'factures');
}
我注册了我的提供商,一切正常,期待 Auth::user() 在视图中返回我 null 和 routes.php。
如何访问自定义服务中的 Auth()?
【问题讨论】:
-
会话中间件是否添加到您的Web中间件阵列的内核文件中?用户登录了吗?
-
是的,来自 routes/web.php 的所有其他路由都可以正常工作,我可以访问 Auth()。仅在新服务中我无法访问 Auth()
标签: laravel authentication view routes service-provider