I am doing the assignment of Teachers - Degrees, that is to say I have a Teaching model and a Grade model and their relationship is of many to many so when it comes to making the migration creates a pivot teacher_graduate table. According to I understand laravel does not use a model in the pivot table. The issue is that to perform this assignment I have to show in the index.blade.php the pivot table (records of the same) and the truth is not how to do it, that is, I do not know how to reference it. In the same way I need to save the assignments in the pivot table.
Teacher table migration.
class CreateDocenteTable extends Migration
{
public function up()
{
Schema::create('docentes', function (Blueprint $table) {
$table->increments('id');
$table->integer('nip')->unique();
$table->string('nombres', 100);
$table->string('apellidos', 100);
$table->string('dui', 12)->unique();
$table->string('nit', 20)->unique();
$table->string('especialidad', 50);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('docentes');
}
}
Table migration Grade.
class CreateGradoTable extends Migration
{
public function up()
{
Schema::create('grados', function (Blueprint $table) {
$table->increments('id');
$table->integer('idturno')->unsigned();
$table->string('nombre', 60);
$table->foreign('idturno')->references('id')->on('turnos')->onDelete('cascade');
$table->timestamps();
});
Schema::create('docente_grado', function (Blueprint $table) {
$table->increments('id');
$table->integer('iddocente')->unsigned();
$table->integer('idgrado')->unsigned();
$table->foreign('iddocente')->references('id')->on('docentes')->onDelete('cascade');
$table->foreign('idgrado')->references('id')->on('grados')->onDelete('cascade');
$table->timestamps();
});
public function down()
{
Schema::dropIfExists('docente_grado');
Schema::dropIfExists('grados');
}
}