Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

How to build Multi-Domain Laravel Application (with demo) #37

Open
maxkostinevich opened this issue May 25, 2018 · 4 comments
Open

How to build Multi-Domain Laravel Application (with demo) #37

maxkostinevich opened this issue May 25, 2018 · 4 comments

Comments

@maxkostinevich
Copy link

https://maxkostinevich.com/blog/multi-domain-laravel

@monaam
Copy link

monaam commented May 25, 2018

If I may suggest something, use the route defaults function to force the subdomain in a middleware

@maxkostinevich
Copy link
Author

@monaam Can you provide an example?

@monaam
Copy link

monaam commented May 27, 2018

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)

@monaam
Copy link

monaam commented May 27, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants