Reputation: 161
I want to add service provider in laravel 11, but i am not sure how to add it using laravel 11. As previous version of laravel, it is added in config/app.php file, but in laravel 11 it needs to be added in packageServiceProvider file within providers folder. Below is my code, please tell me if i am wrong somewhere..
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class PaytmWalletServiceProvider extends ServiceProvider
{
/**
* All of the container bindings that should be registered.
*
* @var array
*/
public $bindings = [
ServerProvider::class => Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,
];
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
Upvotes: 5
Views: 11978
Reputation: 185
An alternative is to call addProviderToBootstrapFile()
in your service provider's register()
method, passing in the concrete class of your service:
...
use App\Services\PaytmWallet;
class PaytmWalletServiceProvider extends ServiceProvider
{
...
public function register(): void
{
ServiceProvider::addProviderToBootstrapFile(PaytmWallet::class);
}
...
}
This will add an entry for the concrete class in bootstrap/providers.php
array.
Upvotes: 1
Reputation: 184
In previous version of Laravel, the providers were registered in config/app.php
file. But in Laravel 11.x most of the configurations are moved to /bootstrap
directory.
In Laravel 11.x and above, bootstrap/providers.php
file returns an array which contains all providers that will be registered in your application.
<?php
return [
App\Providers\AppServiceProvider::class,
...AllYourProvders
];
Upvotes: 12