Lravel

时间:2018-03-23 02:56:51

标签: php laravel

我正在尝试使用Laravel视图编辑器。我在config / app.php中注册了我的课程但是我一直收到以下错误:

  

" Class App \ Http \ ViewComposers \ PostComposer不存在

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use View;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('plain','App\Http\ViewComposers\PostComposer');
    }

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

我的帖子作曲家课

<?php

namespace App\Http\ViewComposer;

use Illuminate\View\View;
use App\Post;

class PostComposer
{
    public function comspose(View $view)
    {
        $posts = Post::all();
        $view->with('postha', $posts );
    }
}

这是我浏览器的屏幕截图:

browser error

![folder structure in my app][]

2 个答案:

答案 0 :(得分:3)

您的命名空间错误。

您从(复数)导入:

App\Http\ViewComposers\PostComposer

但ViewComposer的命名空间不是复数:

pre

答案 1 :(得分:0)

试一试:namespace App\Http\ViewComposernamespace App\Http\ViewComposers