1

http://laravel.com/docs/5.1/facades

Facades are listed on the linked page at the bottom. My question is... How do I override these service container bindings?

Example, the Request facade binds Illuminate\Http\Request with the key request. I want to create my own class which inherits from Illuminate\Http\Request and bind it with the request key, instead of the current class. And I can't find which service provider binds this.

morgoth84
  • 1,070
  • 2
  • 11
  • 25

2 Answers2

3

So, I kind of did it. First I noticed these bindings were hardcoded in Illuminate\Foundation\Application::registerCoreContainerAliases() so I extended this class and overrode this method to change it. I also had to call this class now in bootstrap\app.php, but doing all this didn't help, I was still getting an instance of Illuminate\Http\Request.

So then I discovered that Illuminate\Http\Request was directly referenced in public\index.php so I tried changing it there to My\Very\Own\Http\Request and this worked, finally my implementation was being used.

Finally, I deleted my version of Application::registedCoreContainerAliases() and reverted bootstrap\app.php because everything is also working without this change.

morgoth84
  • 1,070
  • 2
  • 11
  • 25
1

I think the following answer would be very useful for you

https://stackoverflow.com/a/39648307/3912276

I quoted the most important part of the answer. It explains how you can replace/extend the Mailer facade

Write your own implementation of Mailer, extending Illuminate\Mail\Mailer, in which you can override the send method, implement your checks and call parent::send(). Write your own service provider (Extending Illuminate\Mail\MailServiceProvider), in particular re-implement the register method. It should create an instance of your own Mailer in place of Laravel's own. (You can copy most of the code from Laravel's register method). Now, in your config/app.php file, in the providers array, replace Illuminate\Mail\MailServiceProvider::class, with your own provider.

Mark Walet
  • 1,147
  • 10
  • 21