Laravel 5,视图::分享 [英] Laravel 5, View::Share

查看:51
本文介绍了Laravel 5,视图::分享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行view::share('current_user', Auth::User());,但是在laravel 5中我找不到在哪里执行此操作,在L4中,您可以在baseController中执行此操作,但是那个已经不存在了.

I'm trying to do a view::share('current_user', Auth::User()); but in laravel 5 i can't find where to do this, in L4 you could do this in the baseController, but that one doesn't exists anymore.

格兰·格兰特

推荐答案

首先,您可以创建自己的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

这篇关于Laravel 5,视图::分享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆