Service Providers

Statamic is built on top of Laravel, which makes heavy use of Service Providers to bootstrap functionality into the application. Your own addons, as well as all of Statamic's core services are bootstrapped via service providers.


Overview

Service providers are the central place of all Statamic, application bootstrapping. Your own addons, as well as all of Statamic’s core services are bootstrapped via service providers.

But, what do we mean by “bootstrapped”? In general, we mean registering things, including registering service container bindings, event listeners, middleware, and even routes.

Example Class

The class file must be named AddonNameServiceProvider.php.

<?php

namespace ExampleNamespace;

use Illuminate\Support\ServiceProvider;

class ExampleClass extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Generating

You can generate a service provider class file with a console command.

php please make:provider AddonName

Learn More

Read more about Service Providers in the Laravel docs.

Last modified on September 9, 2016