国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

How to pass data to template page in laravel
為情所困
為情所困 2017-05-16 16:51:29
0
2
557

Front-end template layout.blade.php page part code:

<nav>{{ $message }}</nav>
<p class="container">  @yield('content') </p>
<footer></footer>

Other pages inherit this page.

How to pass the message data in nav from the background? Is it passed once in the controller of each content page? This seems very troublesome; another question, how to use Auth::user()->id in the boot() method of AppServiceProvider to obtain the id of the currently logged in user in various ways?

為情所困
為情所困

reply all(2)
淡淡煙草味
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Auth;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * 在容器中注冊綁定.
     *
     * @return void
     * @author http://laravelacademy.org
     */
    public function boot()
    {

        // 使用基于閉包的composers...
        view()->composer('admin.header', function ($view) { 
            $data['order-remind']=null;
            $data['order']=null;
            $data['order-remind']=null;
            $view->with('data',$data);
        });

        view()->composer('admin.nav', function ($view) {
            $user=auth()->guard('admin')->user();
            $view->with('user',$user);
        });

        view()->composer('agent.main', function ($view) {
            $user=auth()->guard('agent')->user();
            $view->with('user',$user);
        });

        view()->composer('account.main', function ($view) {
            $user=auth()->guard('account')->user();
            $wechat=Auth::guard('wechat')->user();
            $view->with('account',$user)->with('wechatAccount',$wechat);
        });

        view()->composer(['wechat.js.index','wechat.activity.vote.main'], function ($view) {
            $app=app('wechat');
            $js=$app->js;
            $view->with('js',$js);
        });

    }

    /**
     * 注冊服務(wù)提供者.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
伊謝爾倫
  1. $message You can directly write php statement query in {{}} of blade template. For example:
    Message::first() or Message::where()... and the like.

  2. The ID of the currently logged in user can also be written directly in the blade

    Auth::user()->id
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template