Support the ongoing development of Laravel.io →
Configuration Database Architecture
Last updated 1 year ago.
0

As for users, I'd keep them in the main database, not in the tenant databases, so you'll only ever have to check that one db for users. As for the other statistical data, have a look at Elasticsearch. It allows you to create multiple indexes (databases in relational speak) and multiple types per index (think tables in a relational db), so you can sync the relevant data from MySQL or similar and then perform various quite powerful queries across any or all indexes.

Last updated 1 year ago.
0

Thanks for your quick reply @shabushabu. Me also having users in main database now. But how can I make foreign key relationships with other tables, If I have users in main database. We have to make relationship such as tenant user with projects and etc.

Last updated 1 year ago.
0

Here's an example:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Query\Expression;

class SomeTable extends Migration
{
    public function up()
    {
        Schema::create('some', function (Blueprint $table)
        {
            // other schema bits

            $table->foreign('user_id')
                ->references('id')
                ->on(new Expression('database.prefix_users'));
        }
    }
}

Basically, if you pass an Expression instance into the on method, then Laravel won't try and do it's bits, like adding the prefix. This lets you add the database name. You just have to make sure to add your table prefix in manually.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.