1
The tables:
- The table
users
, records users who may have N functions that are stored in the tablefuncoes
(student, responsible, teacher, etc). - The table
funcao_user
is pivot that makes the relationship Many To Manyusers
andfuncoes
.
So far, so good.
A user who has a student role can have N users with the responsibility role and, a user who has the responsibility function to have N users with the student role, that is, there is a relationship Many To Many within the users table.
For this relationship, I created the pivot table aluno_responsavel
with the fields:
aluno_id
, responsavel_id
and parentesco
(in relation to parent, indicates parent, etc):
Schema::create('aluno_responsavel', function (Blueprint $table) {
$table->integer('aluno_id')->unsigned();
$table->integer('responsavel_id')->unsigned();
$table->string('parentesco');
$table->foreign('aluno_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('responsavel_id')->references('id')->on('users')->onDelete('cascade');
});
How the relationship between the tables would be users
and aluno_responsavel
in the User model?
Only do referencesMany on both sides for the User Model
– gmsantos
Poxa ... is complicated by the way,
aluno_id
andresponsavel_id
are pointed to the same table and the same field, for me a wrong normalization there ...– novic
Thank you for participating, @Virgilionovic and @gmsantos! I found an argument about the same case with information that’s pretty close to what I’m looking for, but I haven’t been able to test that information yet. When I test I inform the result. ---> https://github.com/laravel/framework/issues/441
– Julio Alves