2016-08-20 76 views
3

我有服務供應商類別,這就要求將View Composer類... 但在運行程序後,顯示我這個錯誤類不存在

類OIMS \ HTTP \ SidebarComposer不存在

ComposerServiceProvide類別:

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); 
    } 

} 

回答

1

正確的命名空間應該是:

namespace Oims\Http; 

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


class SidebarComposer 
1

開始從這個固定的命名空間:

namespace Oims\Http\SidebarComposer; 

要:

namespace Oims\Http;