Closed barthompson closed 10 years ago
With Facades, you end up using a class directly in a model/business logic class. In this way, Facades circumvent the use of dependency injection.
This makes testing and maintainability harder.
Now, technically, a Facade DOES let you swap out what class is used underneath it (That's what you're doing getFacadeAccessor() method in your Facade). So the above points aren't technically true, but they are from a pragmatic standpoint:
I use them in any Laravel class that is not part of my business logic libraries - Almost purely within Controllers. Sometimes within an Eloquent model (not in a "repository", but just within an Eloquent model itself).
Hi there,
I have bought your book 'Implementing Laravel' and have also read most of your blog at Fideloper.com (including the post 'How to Create a Facade in Laravel 4').
From my reading, I understand the code and syntax of using both dependency injection as well as Facades, however, what I am not clear on is when you should use one or the other??
Could you possibly just outline a few simple guidelines as to when to use one or the other and the advantages/disadvantages of each approach?
In fact, it would be particularly helpful if you could add your post on Facades to the book and include a Facade in the 'Implementing Laravel' app to illustrate this distinction.
Many thanks for all your help to date. Both the Book and your blog are excellent!