Laravel

Laravel Service Providers: Bootstrap Your App

January 16, 2026 1 min read 19 views

Bootstrap with service providers:

Create Provider

php artisan make:provider PaymentServiceProvider

Register Method

public function register()
{
    $this->app->singleton(PaymentGateway::class, function ($app) {
        return new StripeGateway(config('services.stripe.key'));
    });
}

Boot Method

public function boot()
{
    View::composer('*', function ($view) {
        $view->with('settings', Settings::all());
    });
}

Register in Config

'providers' => [
    App\Providers\PaymentServiceProvider::class,
],
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!