How to publish service provider to the application in laravel 11
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Welcome to our comprehensive guide on adding service providers in Laravel 11, an up-to-date PHP framework. In this post, we'll discuss the ins and outs of publishing your custom service provider. We will also cover how this process has changed from previous versions of Laravel, where the configuration was done within the config/app.php file, to the current implementation in packageServiceProvider files within a providers folder.
Firstly, let's explain what a service provider is: a class that extends Illuminate\Support\ServiceProvider. Service providers have two main responsibilities - registering and binding services. It means these providers are responsible for defining the dependencies your application will need to function properly. In Laravel 11, you can create one or multiple providers within the Providers folder.
Now let's get down to it. Our example service provider class is called PaytmWalletServiceProvider. It extends Illuminate\Support\ServiceProvider, as shown in our code snippet:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class PaytmWalletServiceProvider extends ServiceProvider
{
// ... (rest of the class)
}
Next, we need to register and bind our service. In the example provided, we've defined a binding for ServerProvider::class (an imaginary class for illustration purposes) with the value Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class, which is also an imaginary class in this scenario. When you have your actual bindings and classes, make sure to update these appropriately.
Finally, we implement our service provider by registering and booting it. This is done through the register() and boot() methods, respectively. These functions are empty in our example, but they would be used to configure and initiate your application's dependencies when necessary.
To publish this service provider to the application, we need to modify the composer.json file located in the root directory of your project. Here you can add a new key-value pair for "providers" with the provider's full namespace path. For instance:
"autoload": {
"classmap": [
"database/seeds",
"app/Models"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories": "database/factories",
"Domain\\ValueObjects": "app/Domains/ValueObjects/"
},
"providers": [
"App\Providers\PaytmWalletServiceProvider"
]
}
Now, run composer dump-autoload to generate the autoload files and reload your project. By including this provider in the providers key of the composer.json, you've successfully published your PaytmWalletServiceProvider to the Laravel 11 application.
To conclude, publishing a service provider involves several steps. Firstly, create a well-structured custom service provider class with its respective bindings and configurations. Then, include it in your project by updating the composer.json file. Finally, run the dump-autoload command to ensure proper autoloading of dependencies.
Remember that the exact process may vary depending on your project's requirements, but this article covers a general approach and best practice for publishing service providers in Laravel 11.