The tables:
- The
users
table registers users who can have N functions that are stored in thefuncoes
table (student, responsible, teacher, etc.). - The
funcao_user
table is pivot that makes the Many To Many relationship betweenusers
andfuncoes
.
So far, everything okay.
A user who has a student role can have N users with the role of respon- sible, and a user who has the role of responsible for having N users with the student role, ie there is a Many To Many relationship within of 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 the parent, indicate 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 would the relationship between the users
and aluno_responsavel
tables in the User model be?