Php 拉威尔5号,can';t使用AppServiceProvider中的引导与视图共享数据

Php 拉威尔5号,can';t使用AppServiceProvider中的引导与视图共享数据,php,laravel,laravel-5,Php,Laravel,Laravel 5,刚刚完成了L5的新安装,根据文档,我正在尝试使用AppServiceProvider类中的一个简单共享方法与所有视图共享数据 <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use View; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * *

刚刚完成了L5的新安装,根据文档,我正在尝试使用AppServiceProvider类中的一个简单共享方法与所有视图共享数据

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use View;

class AppServiceProvider extends ServiceProvider {

/**
 * Bootstrap any application services.
 *
 * @return void
 */

public function boot()
{
    View::share('website', 'test');
}

/**
 * Register any application services.
 *
 * This service provider is a great spot to register your various container
 * bindings with the application. As you can see, we are registering our
 * "Registrar" implementation here. You can add your own bindings too!
 *
 * @return void
 */
public function register()
{
    $this->app->bind(
        'Illuminate\Contracts\Auth\Registrar',
        'App\Services\Registrar'
    );
}
刀片文件:

<h1>Test</h1>
{{ $website }}
测试
{{$website}
这应该很容易,所以我想知道我是否在安装阶段犯了一个非常明显的错误


谢谢

您很可能应该通过运行以下命令来清除
compiled.php
文件:

php artisan clear-compiled
或者手动删除
vendor/compiled.php
(在以前的L5版本中是
storage/framework/compiled.php


这是解释。Laravel预编译基本上用于每个请求的特定类。这有助于性能优化。要编译的文件可以在
文件
下的
config/compile.php
中指定。下面的示例如下所示:

'files' => [
    realpath(__DIR__.'/../app/Providers/AppServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/BusServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/ConfigServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/EventServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/RouteServiceProvider.php'),
],

这意味着,如果您更改其中一个预编译文件,则不会立即应用更改(如果存在
compiled.php
),而只能在再次运行
php artisan optimize
或运行
php artisan clear compiled
清除
compiled.php
文件后应用更改。

谢谢,我调用了该命令,得到一个错误:调用未定义的方法illumb\Foundation\Application::getCachedCompilePath()。所以我删除了vendor/compiled.php并运行了composer更新,这就解决了问题?什么不起作用?见下文。最初的composer安装可能有问题。我手动删除了vendor/compiled.php文件,并再次运行composer更新。
'files' => [
    realpath(__DIR__.'/../app/Providers/AppServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/BusServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/ConfigServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/EventServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/RouteServiceProvider.php'),
],