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.
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community