更新时间:2023-11-26 10:28:04
首先,您可以创建自己的BaseController并将其扩展到其他控制器中.
First, you can probably create your own BaseController and extend it in other controllers.
第二件事是,您可以直接在View中使用Auth:user()
,而无需在视图中分配任何内容.
Second thing is, that you may use Auth:user()
directly in View, you don't need to assign anything in the view.
对于其他用法,您可以转到app/Providers/App/ServiceProvider.php
,在boot
方法中可以View::share('current_user', Auth::User());
,但是当然,您首先需要添加导入名称空间:
For other usages you can go to app/Providers/App/ServiceProvider.php
and in boot
method you can View::share('current_user', Auth::User());
but or course you need to add importing namespaces first:
use View;
use Auth;
因为此文件位于App\Providers
命名空间中
because this file is in App\Providers
namespace