@darrion.kuhn
To load a custom service provider in Laravel, follow these steps:
- 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
- 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();
});
}
}
- In the config/app.php file, add your custom service provider to the providers array.
'providers' => [
// Other Laravel service providers
AppProvidersCustomServiceProvider::class,
],
- Run the following command to clear the application cache and optimize the application configuration.
php artisan optimize
- 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.