找不到Symfony \组件\调试\异常\ FatalThrowableError(E_ERROR)类'App \ Providers \ View'

时间:2018-07-19 16:36:57

标签: laravel

AppServiceProvider.php文件上的运行时错误。遵循我的代码

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Illuminate\Support\Facades\Schema;

use App\Category;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        View::share('name','bitm');

        View::composer('frontEnd.includes.menu',function($view){


            $publishedCategories = Category::where('publicationStatus',1)->get();

            $view->with('publishedCategories',$publishedCategories);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

您缺少名称空间\Illuminate\Support\Facades\View::share()

use \Illuminate\Support\Facades\View;

修改

正如@ d3jn所指出的,正确的方法就是use View;