ashokgelal / townhouse

A multi-tenant Laravel app for listing property rentals
https://medium.com/@ashokgelal/writing-a-full-featured-multi-tenant-laravel-app-from-scratch-a0e1a7350d9d
253 stars 86 forks source link

How can i organise web.php routs and judge which tenant in controller for url 'boise.townhouse.dev/show' #13

Open singler009 opened 6 years ago

singler009 commented 6 years ago

Hello, How can i organise web.php routs and judge which tenant in controller for url 'boise.townhouse.dev/show'. I have no idea to handle Hyn\Tenancy!

thank you!

singler009 commented 6 years ago

And where can i find tenant`s config of db connection ?

luceos commented 6 years ago

@singler009 tenant configuration for the database are created on the fly.

colinmackinlay commented 5 years ago

In RouteServiceProvider.php

public function map(Router $router)
    {
.....
        **$this->mapTenantRoutes($router);**
.....
    }

    protected function mapTenantRoutes(Router $router)
    {
        $router->middleware(['web', 'tenancy.enforce'])
            ->domain('{account}.yourapphostname')
            ->namespace($this->namespace)
            ->as('tenant.')
            ->group(base_path('routes/tenant/mytenantroutes.php'));
}

In mytenantroutes.php:

use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'profile'], function () {
    Route::get('/', 'MyControllerController@action')->name('controller.action'); 
});