Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Why not just create an institution table and add an institution_id foreign key in your other tables?

0

KevinCreel said:

Why not just create an institution table and add an institution_id foreign key in your other tables?

this will word. yes

you can also try writing a wrapper layer that automatically selects the working database based on the sub domain. (multi tenancy) there are many tutorials if you search by the correct keywords

0

I'd suggest doing multi-tenant application which has separate databases for each school.

You do NOT want to show student data to other schools or people. By having separate databases you keep your data separate!

0

I tried what Kevin and astroanu suggest, but i think is not the best way. Maybe im wrong...

illuminate3 said:

I'd suggest doing multi-tenant application which has separate databases for each school.

You do NOT want to show student data to other schools or people. By having separate databases you keep your data separate!

Thats what im trying to do now, but im not sure how i have to this. My approach is having a main DB with the users table, maybe connection table, roles, permissions...

I know that i can define relations across multiple databases, but in order to achieve what i want, how i define the relation , considering that could be in a different database? and where i should define the pivot table to the relations of users on the MAIN-DB and, for example, grades on DB-B?

###-------------EDIT---------------- what im doing now, is trying to stablish the relationship between users, and grades, but i dont know how to do this, because users is on the MAIN_DB, and grades is in the SCHOOL_DB, if i put the pivot table in MAIN, how i reference the FK, of the GRADE if the database changes?

For example in this case, i cannot simply do this:

public function up()
{
	Schema::create('usuario_grupo', function (Blueprint $table) {
        $table->integer('user_id')->unsigned();
        $table->integer('grupo_id')->unsigned();

        $table->foreign('user_id')->references('id')->on('users')
            ->onUpdate('cascade')->onDelete('cascade');

        */ I cannot refer the name of the DB of the school because this name change with every school /*
        $table->foreign('grupo_id')->references('id')->on('schoolA.grupos')
            ->onUpdate('cascade')->onDelete('cascade');

        $table->primary(['user_id', 'grupo_id']);
    });
}

Any suggestion of how i should do this?

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

rolinad rolinad Joined 6 Jul 2015

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.