Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Service Providers: Bootstrap Your App

Understand and create service providers to bootstrap your application.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Create Provider
  2. Register Method
  3. Boot Method
  4. Register in Config

Bootstrap with service providers:

Create Provider

php artisan make:provider PaymentServiceProvider

Register Method

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

Boot Method

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

Register in Config

php
'providers' => [
    App\Providers\PaymentServiceProvider::class,
],
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read