Ad

Is This Considered To Be A Custom Facade Approach In Laravel?

I have piece of functionality that identifies access by a given token (string). If a valid token is given the session should be populated with a valid entry (using the SessionInterface). I've set up my VerifyToken middleware and would like to use a Guard-like approach for my token validation and session storage.

My question, is this type of functionality considered to be a facade in Laravel? If so; what would be the appropiate location to store these files (e.g. app\Facades and also a app\Facades\Contracts to store the interfaces)?

Ad

Answer

A Facade in Laravel is only a way to resolve a binding from the service container.

So, to me, Facades aren't considered as 'application functionality' themselves, but instead as a way to access services (that provide functionality) stored in your Service Container

That being said, if you want to build services with a Guard-like approach, i think that, as usual, the directory structure is up to you: Laravel is very flexible in this context

Once you have built your service classes, if you think that it would be useful, you could implement one or more Facades to access some of the services.

Personally i'm not a big Facade fan, i think it's better to use Dependency Injection ( via method or constructor parameters ) where possible: this will inject your services where needed, but in the same time keeping your code-dependencies more clear, as they are immedialty visible from the method's signature

Ad
source: stackoverflow.com
Ad