I actually am liking this method used in this series ... https://laracasts.com/series/multitenancy-in-practice
It uses a session variable that is set on user login. And some global scopes. Its pretty clean...
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I haven't been able to find a suitable pattern to clean up my controller classes, and perhaps it's because it's an anti-pattern to begin with. Consider a multi-tenancy application, where the sub-domain relates to some model (say, "Customer"). Route model binding works fine, but feels bloated and possibly inefficient for every controller/method to need to reference it:
public function index(Request $request, Customer $customer, ...)
Additionally, I may want to be able to reference the bound model outside of a controller, but if it's not been loaded via a controller parameter, request()->customer is the slug, not the model.
Is there a preferred way, perhaps a middleware or extending the Request class, to make the Customer model more accessible throughout the application, instead of being so closely tied to calling a controller method?
Please or to participate in this conversation.