2017-10-23 1 views
1

를 찾을 수 없습니다 얻을 내가 PARAM 폼 ENV를 보낼 수있는 내 자신의 ServiceProvider를 만들 때 개시 클래스 :방법이

class InstagramServiceProvider extends ServiceProvider 
{ 
    protected $defer = true; 

    public function boot() 
{ 
    $this->publishes([ 
     __DIR__.'/../config/config.php' => config_path('instagram.php'), 
    ]); 
} 
public function register() 
{ 
    $this->app->bind('instagram.client', function ($app) { 
     return new InstagramClient([ 
      'apiKey' => $app['config']->get('instagram.clientId'), 
      'apiSecret' => $app['config']->get('instagram.clientSecret'), 
      'apiCallback' => $app['config']->get('instagram.redirectUri'), 
      'scope' => $app['config']->get('instagram.scope'), 
     ]); 
    }); 
} 
public function provides() 
{ 
     return array('instagram.client'); 
} 
} 

내가 설정에서 데이터를 얻을 수 없다? 내가 뭘 잘못 했니?

답변

0

Laravel에는 config()이라는이 작업을 위해 특별히 제작 된 기능이 있습니다.

public function register() 
{ 
    $this->app->bind('instagram.client', function ($app) { 
     return new InstagramClient([ 
      'apiKey' => config('instagram.clientId'), 
      'apiSecret' => config('instagram.clientSecret'), 
      'apiCallback' => config('instagram.redirectUri'), 
      'scope' => config('instagram.scope'), 
     ]); 
    }); 
} 

은 또는 당신과 같이 브라켓 표기법을 사용할 수 있습니다 :

$app['config']['instagram']['clientId'] 

자세한 내용은 설명서를 참조하십시오 : https://laravel.com/docs/5.4/configuration#accessing-configuration-values

+1

또한'$ 응용 프로그램의 [ '을 사용할 수 있습니다 다음과 같이 사용할 수 있습니다 config '] ['instagram '] ['clientId ']'등 – Neat

+0

아, 위대한 분! 나는 그것을 추가 할 것이다. :-) –