What are Service Providers in Laravel?

If Laravel was a house, Service Providers would be the electricians, plumbers, and carpenters who set everything up before you move in.

In simple words:

Service Providers are the central place where Laravel loads and registers everything your app needs before it starts running.

They tell Laravel:

  • Which services to load
  • Which bindings to register
  • Which events, routes, or configurations to prepare

Without them, Laravel would be like a shop without shelves — nothing in place to start business.

Where Are Service Providers Located?

All Service Providers live in the app/Providers folder.

Laravel comes with some pre-installed Service Providers in Laravel 12 like:

AppServiceProvider

You can create your own too.

Main Methods in a Service Provider

Every Service Provider has two main methods:

1. register() – This is where you tell Laravel what to load into the Service Container.

public function register()
{
    $this->app->bind('MyService', function () {
        return new \App\Services\MyService();
    });
}

2. boot() – This is where you do things after all services are registered.

public function boot()
{
    \Log::info('App is booting...');
}


Creating a Custom Service Provider

php artisan make:provider MyServiceProvider

Then, register it in bootstrap/providers.php:

return [
App\Providers\CustomProvider::class,
];


In Short

Service Providers = Laravel’s setup team

register() = Prepare tools

boot() = Start working

They make Laravel ready to run in an organized way.

Comments