类不存在

时间:2016-08-20 11:06:02

标签: class laravel view

我有服务提供商类,这称为View Composer类... 但运行程序后显示此错误

  

Class Oims \ Http \ SidebarComposer不存在

ComposerServiceProvide Class:

namespace Oims\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\View\Factory as ViewFactory;

class ComposerServiceProvider extends ServiceProvider
{

    public function boot(ViewFactory  $view)
    {
       $view->composer('layout.sidebar','Oims\Http\SidebarComposer');

    }

SidebarComposer类:

namespace Oims\Http\SidebarComposer;

use Oims\Menus;
use Illuminate\Contracts\View\View;


class SidebarComposer
{


    public function compose(View $view)
    {
            $menus =Menus::all();
            $view->with('menus',$menus);
    }

}

2 个答案:

答案 0 :(得分:1)

从修复命名空间开始:

namespace Oims\Http\SidebarComposer;

要:

namespace Oims\Http;

答案 1 :(得分:1)

正确的命名空间应该是:

namespace Oims\Http;

use Oims\Menus;
use Illuminate\Contracts\View\View;


class SidebarComposer