0
我做了一個serviceprovider,並在app.php中添加提供程序,但我該如何使用它?laravel創建服務提供商
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Helpers\api\gg\gg;
class ApiServiceProvider extends ServiceProvider
{
protected $defer = true;
public function boot()
{
}
public function register()
{
$this->app->bind(gg::class, function()
{
return new gg;
});
}
public function provides()
{
return [gg::class];
}
}
GG類是在應用程序\助手\ API \ GG文件夾,我想在任何地方使用這個類像
gg::isReady();
app.php
'providers' => [
...
App\Providers\ApiServiceProvider::class,
...
]
的HomeController @指數
public function index()
{
//how can use this provider in there ?
return view('pages.home');
}
我會嘗試。謝謝 – Hanik