Using "App" Facade or "app()" Helper
use App\Services\Transistor; use Illuminate\Support\Facades\App; // Using the "App" facade $transistor = App::make(Transistor::class); // Using the "app" helper method app(Transistor::class);
Calling from Service Provider
If you want to call it from the Service Provider then you can write your code like below. Do note that it's accessible from within the "$this->app" property.
$this->app // get Laravel underlying provider
<?php namespace App\Providers; use App\Services\Riak\Connection; use Illuminate\Support\ServiceProvider; class RiakServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { $this->app->singleton(Connection::class, function ($app) { return new Connection(config('riak')); }); } }
Leave a reply