Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

Single DB Multi-tenancy without using Package in Laravel

I am trying to develop a multi-tenancy application without using Package in Laravel-5.8.

I am using traits and scopes

Models

class Company extends Model
{
    protected $table = 'companies';

    protected $fillable = [
       'id',
       'company_code',
       'company_name'
   ];
}

class User extends Authenticatable
{
  protected $fillable = [
   'name',
   'company_id',
   'email',
 ];
}

The main domain is:

https://myapp.com

Sub domains are:

https://company1.myapp.com

https://company2.myapp.com

I using socialite for login authentication. For the main company:

config/services.php

'azure' => [
   'client_id' => env('AZURE_KEY','23333-ff333-9103-fgghhh-cc8b955ed23c'),
   'client_secret' => env('AZURE_SECRET','ffjjfnfhfhhhhff'),
   'redirect' => env('AZURE_REDIRECT_URI','https://myapp.com/login/azure/callback')
],

config/mail.php

 return [
   'driver' => env('MAIL_DRIVER', 'smtp'),
   'host' => env('MAIL_HOST', 'smtp.office365.com'),
   'port' => env('MAIL_PORT', 587),

   'from' => [
       'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
       'name' => env('MAIL_FROM_NAME', 'COMPANY1'),
   ],

   'encryption' => env('MAIL_ENCRYPTION', 'tls'),
   'username' => env('MAIL_USERNAME','[email protected]'),
   'password' => env('MAIL_PASSWORD','maincompany'),    
   'sendmail' => '/usr/sbin/sendmail -bs',

   'log_channel' => env('MAIL_LOG_CHANNEL'),
];

How do I treat:

config/services.php and config/mail.php

for the three companies https://myapp.com, https://company1.myapp.com and https://company2.myapp.com

Thanks

question from:https://stackoverflow.com/questions/65887455/single-db-multi-tenancy-without-using-package-in-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...