douyanning3724 2019-06-26 01:06
浏览 206

如何获取公共布局文件的数据并在所有视图上显示

I have a common layout file which use to extend the common features such as navbar footer. So now I need to get data from my database eg: number of users in navbar and to display them in all views. So my common layout file has no controllers or routes. How can I do it?

  • 写回答

1条回答 默认 最新

  • doudanma9706 2019-06-26 01:25
    关注

    You can use AppServiceProvider's boot function to pass variable to specific view or multiple views with view Composer. Try using following example.

    public function boot()
    {
        \View::composer('url_here', function ($view) {
            $view->with('$post', \App\Post::all());
        });
    }
    

    here is the official documentation.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序