Skip to content
Advertisement

Laravel Facades – Passing parameter to __construct()

If I am creating a Facade, and I want to pass parameters before it becomes instantiated, what do I do?

Advertisement

Answer

The facade’s underlying service is resolved through the IoC container, so all you have to do is bind it correctly.

Create a Service Provider, and pass in whatever you want:

JavaScript

Don’t forget to load the service provider in your app’s config array.

Then use that bound key in your facade:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement