I have built a Laravel 5.4 application with a custom facade, App\Facades\Repo
. The Repo facade proxies to a RepositoryFactory
class. In my app configuration I have an alias Repo
which points to the Repo facade. I use it to get repositories with calls such as Repo::get('User')
.
This works fine if I am in a controller or the routes file. In other parts of the application however, I can't use the Repo
alias. The interpreter looks for a Repo class in the current namespace, and errors out. This raises two questions:
- Which classes are aware of the facade aliases? What defines them?
- In classes that are not aware of facade aliases, should I go ahead and import the facade class itself? Or is this a code smell?
By way of example, classes which are not alias-aware include my repositories themselves. I have created a super-type for them, but they don't inherit from any Laravel class. Sometimes my repositories need to call on other repositories to do their work.