2017-10-23 3 views
1
gefunden zu

ich meine eigenen Serviceprovider erstellen param Form ENV als Initiations Klasse senden:Methode nicht

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

Und ich kann nicht Daten von Config? Was ich falsch mache?

Antwort

0

Laravel hat eine speziell für diesen Job entwickelte Funktion namens config(). Sie können es wie folgt:

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

Weitere Informationen siehe Dokumentation: https://laravel.com/docs/5.4/configuration#accessing-configuration-values

+1

Sie könnten auch '$ app [verwenden‘

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'), ]); }); } 

Alternativ Sie eine Klammer-Notation wie so verwenden könnte config '] [' instagram '] [' clientId '] 'usw. – Neat

+0

Ahh, toller! Ich füge das hinzu. :-) –

Verwandte Themen