2017-12-29 14 views
0

PHP를 사용하여 navbar를 생성하는 플러그인이 있습니다. 폴더는 프로젝트에/설정/menu.phpLaravel의 config 폴더에서 모델을 사용할 수 없습니다.

그것은 다음과 같습니다

나는 몇 가지 모델 정보를 추가 할
<?php 

return [ 

//HORIZONTAL MENU LAYOUT - MENU 

    'horizontal' => [ 
     [ 
      'title' => 'bar', 
      'link' => '/bar/all', 
      'active' => 'bar*', 
      'icon' => 'fa fa-sign-in', 

     ], 
     [ 
      'title' => 'foo', 
      'link' => '/foo/all', 
      'active' => 'foo*', 
      'icon' => 'fa fa-sign-out', 
     ], 
    ] 
]; 

.

<?php 
use Auth; 
$id = Auth::user()->id; 

return [ 

//HORIZONTAL MENU LAYOUT - MENU 

    'horizontal' => [ 
     [ 
      'title' => 'bar', 
      'link' => '/bar/'. $id, 
      'active' => 'bar*', 
      'icon' => 'fa fa-sign-in', 

     ], 
     [ 
      'title' => 'foo', 
      'link' => '/foo/all', 
      'active' => 'foo*', 
      'icon' => 'fa fa-sign-out', 
     ], 
    ] 
]; 

내가이 오류 : Class 'Auth' not found

내 시도이다. 또한 모델을 시도했다 :

나에게이 오류 제공
$model = \App\Model::count(); 

: 나는이 모델은 여기에 어떻게 사용합니까

Call to a member function connection() on null 

를?

답변

3

laravel config는 다른 것들보다 먼저로드되므로 모델을 인스턴스화하면 오류가 발생하며이 오류는이 특정 구성 파일이로드되는 동안로드 된 데이터베이스 연결 정보가 없기 때문에 발생합니다.

<?php 

return [ 

//HORIZONTAL MENU LAYOUT - MENU 

    horizontal' => [ 
     [ 
      'title' => 'bar', 
      'link' => '/bar/%d', // here %d is userId from database 
      'active' => 'bar*', 
      'icon' => 'fa fa-sign-in', 

     ], 
     [ 
      'title' => 'foo', 
      'link' => '/foo/all', 
      'active' => 'foo*', 
      'icon' => 'fa fa-sign-out', 
     ], 
    ] 
]; 

을 나중에 모델 값이 %d 교체 : 나는 당신이 설정에서 모델을 호출해야하는 이유, 당신은 단순히 아래와 같은 메뉴 레이아웃의 템플릿 같은 것을 만들 수 있을까.