使用View Composer,但无法到达我的视野

时间:2018-10-24 08:19:30

标签: laravel-5.4

我试图在多个页面(不是全部)中使用相同的口才数据。 Class::isInstance()中需要数据 为此,我第一次使用view :: composer。 我遵循了laravel(5.4)网站上的文档。

我创建了以下内容:

App \ Providers \ ComposerServiceProvider

'view/board/segments/header'

App \ Http \ ViewComposers \ Board \ MemberSettingsComposer

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider
{
    public function boot()
    {

        view()->composer(
            'layouts.board.main',
            'App\Http\ViewComposers\Board\MemberSettingsComposer'
        );

    }

    public function register()
    {
        //
    }
}

资源/视图/布局/board/main.blade.php

<?php

    namespace App\Http\ViewComposers\Board;

    use Illuminate\View\View;

    use Auth;
    use App\Models\BoardmembersDashboardSettings;


    class MemberSettingsComposer {

        public $settings;

        public function __construct()
        {

            //$this->settings = BoardmembersDashboardSettings::find(Auth::user()->id);

            $this->settings = BoardmembersDashboardSettings::where('id', Auth::user()->id)->first();

        }

        public function compose(View $view)
        {

            $view->with(compact('settings', $this->settings));
        }

    }

我尝试了几种选择:

  • 将呈现的视图从<!DOCTYPE html> <html lang="en"> <!-- Start including header --> @include('board.segments.header') <!-- End including header--> <body class="framed main-scrollable"> <div class="wrapper"> <nav class="navbar navbar-static-top header-navbar"> <!-- Start include Mobile Navigation --> @include('board.segments.navmobile') <!-- End include Mobile Navigation --> <!-- Start include Brand Navigation --> @include('board.segments.navbrand') <!-- End include Brand Navigation --> <div class="topnavbar"> <!-- Start include Top Navigation Left--> @include('board.segments.navtopleft') <!-- End include Top Navigation Left --> <!-- Start include Top Navigation Right --> @include('board.segments.navtopright') <!-- End include Top Navigation Right --> </div> </nav> <div class="dashboard"> <div class="sidebar"> <div class="quickmenu"> <div class="quickmenu__cont"> <div class="quickmenu__list"> <div class="quickmenu__item active"> <div class="fa fa-fw fa-home"></div> </div> <div class="quickmenu__item"> <div class="fa fa-fw fa-envelope-o"></div> </div> <div class="quickmenu__item new"> <div class="fa fa-fw fa-comments-o"></div> </div> <div class="quickmenu__item"> <div class="fa fa-fw fa-feed"></div> </div> <div class="quickmenu__item"> <div class="fa fa-fw fa-cog"></div> </div> </div> </div> </div> <div class="scrollable scrollbar-macosx"> <div class="sidebar__cont"> <!-- Start include Side Menu Pages --> @include('board.segments.sidemenupages') <!-- End include Side Menu Pages --> <!-- Start include Side Menu Mail --> @include('board.segments.sidemenumail') <!-- End include Side Menu Mail --> <!-- Start include Side Menu Messages --> @include('board.segments.sidemenumessages') <!-- End include Side Menu Messages --> <!-- Start include Side Menu Activity --> @include('board.segments.sidemenuactivity') <!-- End include Side Menu Activity --> <!-- Start include Side Menu Settings --> @include('board.segments.sidemenusettings') <!-- End include Side Menu Settings --> </div> </div> </div> <div class="main"> <div class="main__scroll scrollbar-macosx"> <div class="main__cont"> <div class="main-heading"> <div class="main-title"> <!-- Start include Breadcrumb --> @include('board.segments.breadcrumb') <!-- End include Breadcrumb --> </div> <div class="main-filter"> <!-- Start include Search --> @include('board.segments.search') <!-- End include Search --> </div> </div> @yield('content') </div> </div> </div> </div> </div> <!-- Start include Footer --> @include('board.segments.footer') <!-- End include Footer --> </body> </html> 更改为'layouts.board.main'
  • 在我能想到的每个地方都使用了'board.segments.header'。唯一不起作用的地方是视图。

4次出现以下错误。

dd($this->settings)

有人知道什么地方可能出了问题,然后尝试向我解释吗?

0 个答案:

没有答案