マルチテナントアーキテクチャで開発したい
$ php -v
PHP 7.4.11 (cli) (built: Oct 21 2020 19:12:26) ( NTS )
$ composer create-project laravel/laravel multi –prefer-dist
$ cd multi
$ php artisan -V
Laravel Framework 8.27.0
$ composer require laravel/jetstream
$ php artisan jetstream:install livewire
multi tenant laravel
tenacy
https://tenancy.dev/
L 簡単にマルチテナントを構築できるhyn/multi-tenant
### 概要
– テナントデータベースはテナント1つにつき1つとする
– テナントを作ると、テナントデータベース、専用ユーザが作られる。テナントを削除すると削除される
– システムのmigrationとテナントmigrationは分ける
### Tenancy Install
tenancy
mysql> CREATE DATABASE IF NOT EXISTS tenancy;
mysql> CREATE USER IF NOT EXISTS tenancy@localhost IDENTIFIED BY ‘hogehoge’;
mysql> GRANT ALL PRIVILEGES ON *.* TO tenancy@localhost WITH GRANT OPTION;
mysql> show databases;
config/database.php
'connections' => [ 'system' => [ 'driver' => 'mysql', 'host' => env('TENANCY_HOST', '127.0.0.1'), 'port' => env('TENANCY_PORT', '3306'), 'database' => env('TENANCY_DATABASE', 'tenancy'), 'username' => env('TENANCY_USERNAME', 'tenancy'), 'password' => env('TENANCY_PASSWORD', 'fugafuga'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ],
.envからDBに関する情報を削除する
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=
config/database.php
L mysqlからsystemに変更する
'default' => env('DB_CONNECTION', 'system'),
$ composer require “hyn/multi-tenant:5.6.*”
./composer.json has been updated
Running composer update hyn/multi-tenant
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
– hyn/multi-tenant[5.6.0, …, 5.6.1] require ramsey/uuid ^3.5 -> found ramsey/uuid[3.5.0, …, 3.x-dev] but the package is fixed to 4.1.1 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
– hyn/multi-tenant[5.6.2, …, 5.6.4] require laravel/framework ^7.0 -> found laravel/framework[v7.0.0, …, 7.x-dev] but it conflicts with your root composer.json require (^8.12).
– Root composer.json requires hyn/multi-tenant 5.6.* -> satisfiable by hyn/multi-tenant[5.6.0, …, 5.6.4].
Use the option –with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
なにこれ? Laravel8系に対応してないってこと??