blog-contest-may-mayhem
blog-contest-may-mayhem copied to clipboard
How to build Multi-Domain Laravel Application (with demo)
https://maxkostinevich.com/blog/multi-domain-laravel
If I may suggest something, use the route defaults function to force the subdomain in a middleware
@monaam Can you provide an example?
For example, in my multi tenant apps I often use this code
app('url')->defaults(['host' => $request->route('host')]);
$request->route()->forgetParameter('host');
And then whenever I use the route()
helper the host get inserted by default without the need of another helper function (for the sake of simplicity)
The second line actually removes the $host
parameter from controllers, so I dont have to pass it through all controller methods for example
public function saveCategory(Request $request, Category $category){ ... }
Instead of
public function saveCategory(Request $request, Host $host, Category $category){ ... }
But to make it work you need a singleton instance of your host model binded to the container, and you load it when initializing the tenant in your middleware