As we have already discussed, the
collection API from Laravel is a good example of an immutable data structure with nice functional methods on top of it. The database layer returning instances of the
Collection class really helps with streamlining its use.
However, the Facade pattern proposed by the framework is a no-go if you want to keep your functions pure. As soon as you use a façade, you end up using an external dependency that is not declared in your function signature.
Whatever your take on this pattern is, if you want to write referentially transparent code, you have to get rid of them. Luckily, Laravel provides helper functions for most common tasks and a way to access the container that is baking the facade. As we will see, it ...