Why don't you just simply create a relation manager on the classrooms to attach/detach students? It looks like all the relationship are already there.
Filament Multiple Many to Many Relation Resource Management
Hello,
I have been working on a school management project. My models are Semester, Classroom & Student. Each semester can have multiple class and each class can be open for teaching for any semester. Since it is one-level-deep many-to-many relation, I have managed to complete this filament relation. However, every classroom has also many student. I first create semester then attach some classes but I also want to attach student to this classroom that is attached to the semester. This phase is what i have problem creating. I thought about multi-tenancy but my requirements is not meet for it.
I am open to any suggestion to improve myself in this topic. Thank you in advance. If you have any question about any clarity, feel free to ask.
My tables are;
Schema::create('semesters', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamp('start_date');
$table->timestamp('end_date');
$table->timestamps();
$table->softDeletes();
});
Schema::create('classrooms', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code');
$table->foreignId('responsible_personnel_id')->constrained('personnels')->cascadeOnDelete();
$table->foreignId('reserve_responsible_personnel_id')->constrained('personnels')->cascadeOnDelete();
$table->integer('floor');
$table->string('responsible_parent_name');
$table->string('responsible_parent_phone');
$table->timestamps();
$table->softDeletes();
});
Schema::create('classroom_semester', function (Blueprint $table) {
$table->id();
$table->foreignId('semester_id')->constrained()->cascadeOnDelete();
$table->foreignId('classroom_id')->constrained()->cascadeOnDelete();
$table->timestamps();
});
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('surname');
$table->string('code');
$table->timestamp('birth_date');
$table->string('mother_name');
$table->string('father_name');
$table->longText('address');
$table->string('phone_1');
$table->string('phone_2')->nullable();
$table->string('phone_emergency')->nullable();
$table->string('city');
$table->string('district');
$table->string('education_type')->default(EducationType::FULL_TIME);
$table->timestamps();
$table->softDeletes();
});
Schema::create('classroom_student', function (Blueprint $table) {
$table->id();
$table->foreignId('classroom_id')->constrained()->cascadeOnDelete();
$table->foreignId('student_id')->constrained()->cascadeOnDelete();
$table->timestamps();
});
My models are
Semester.php
public function classrooms()
{
return $this->belongsToMany(Classroom::class)->withTimestamps();
}
Classroom.php
public function semesters()
{
return $this->belongsToMany(Semester::class)->withTimestamps();
}
public function students()
{
return $this->belongsToMany(Student::class)->withTimestamps();
}
Student.php
public function classrooms()
{
return $this->belongsToMany(Classroom::class)->withTimestamps();
}
Please or to participate in this conversation.