Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Barry van Veen:
Laravel service provider examples
Nov 15, 2016 @ 15:44:31

In this recent post to his site Barry van Veen introduces you to providers in Laravel applications and how they relate back to the built-in service provider.

Currently, I'm working on my first Laravel package. So, it was time to dive into the wonderful world of the service container and service providers.

Laravel has some great docs about, but I wanted to see some real-world examples for myself. And what better way than to have a look at the packages that you already depend on?

This post details the different things that a service provider can be used for, each taken from a real open-source project. I've linked to the source of each example.

He starts off talking about (and linking to) the current provider documentation and includes a basic example of adding the provider to your configuration. He then covers several different pieces of functionality that can be used inside the providers including:

  • binding of singletons and instances
  • setting up aliases
  • registering dependencies
  • adding in additional resources

There's also a few "other" things included showing how to defer loading, set up event listeners and adding in a new Blade directive.

tagged: laravel service provider introduction tutorial example

Link: https://barryvanveen.nl/blog/34-laravel-service-provider-examples


Trending Topics: