Super APP - Laravel Multitenancy Example

Introduction

A Multitenancy example project using Laravel 8 and Spatie Laravel Multitenancy package

Code Samples

app\Http\Kernel.php

'tenant.web' => [
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,     \Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
],
'tenant.api' => [
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
],

config/multitenancy.php

'enabled' => env('MULTITENANCY_ENABLED', false),
//...

app/Providers/RouteServiceProvider.php

$api = ['api'];
$web = ['web'];

if (config('multitenancy.enabled')) {
  array_push($api, 'tenant.api');
	array_push($web, 'tenant.web');
}

Route::prefix('api')
	->middleware($api)
  ->namespace($this->namespace)
  ->group(base_path('routes/api.php'));

Route::middleware($web)
	->namespace($this->namespace)
  ->group(base_path('routes/web.php'));

Installation

Clone reposository

git clone git@github.com:victoryoalli/superapp.git

Install PHP packages using composer

composer install

Install Javascript/Node packages using npm

npm install && npm run dev

Create a Database superapp

Copy .env.example to .env

Follow the instructions (ESPAÑOL)

Laravel Meetup - Multitenancy

Final project code

git fetch
git checkout meetup

or

Youtube Channel ELiberio - Laravel Multi-Tenancy

Final project code

git fetch
git checkout webinar