How to load custom service provider in laravel?

by darrion.kuhn , in category: PHP Frameworks , 5 months ago

How to load custom service provider in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , 5 months ago


To load a custom service provider in Laravel, follow these steps:

  1. Create a new service provider class: Run the following command in your terminal to create a new service provider class. php artisan make:provider CustomServiceProvider
  2. Open the created service provider file (CustomServiceProvider.php) in the app/Providers directory and register your custom service provider by overriding the register() method. app->bind('CustomService', function ($app) { return new AppServicesCustomService(); }); } }
  3. In the config/app.php file, add your custom service provider to the providers array. 'providers' => [ // Other Laravel service providers AppProvidersCustomServiceProvider::class, ],
  4. Run the following command to clear the application cache and optimize the application configuration. php artisan optimize
  5. Now you can use your newly created custom service by resolving it from the container.

That's it! Your custom service provider is now loaded and can be used throughout your application.