diff --git a/app/Models/Admin.php b/app/Models/Admin.php new file mode 100644 index 0000000..7d76602 --- /dev/null +++ b/app/Models/Admin.php @@ -0,0 +1,17 @@ +belongsToMany(Subject::class); } + public function students(): HasMany + { + return $this->hasMany(Student::class); + } + + public function teachers(): BelongsToMany + { + return $this->belongsToMany(Teacher::class); + } + public function scopeFilter(Builder $query): void { $name = request('name'); diff --git a/app/Models/Student.php b/app/Models/Student.php new file mode 100644 index 0000000..28efe00 --- /dev/null +++ b/app/Models/Student.php @@ -0,0 +1,24 @@ +belongsTo(Grade::class); + } +} diff --git a/app/Models/Subject.php b/app/Models/Subject.php index 5126923..7cc7d1d 100644 --- a/app/Models/Subject.php +++ b/app/Models/Subject.php @@ -20,6 +20,11 @@ class Subject extends Model return $this->belongsToMany(Grade::class); } + public function teachers(): BelongsToMany + { + return $this->belongsToMany(Teacher::class); + } + public function scopeFilter(Builder $query): void { $name = request('name'); diff --git a/app/Models/Teacher.php b/app/Models/Teacher.php new file mode 100644 index 0000000..2a6ea4e --- /dev/null +++ b/app/Models/Teacher.php @@ -0,0 +1,29 @@ +belongsToMany(Subject::class); + } + + public function grades(): BelongsToMany + { + return $this->belongsToMany(Grade::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index def621f..407a732 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,7 +17,6 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', 'email', 'password', ]; diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..d8d8ede 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -13,7 +13,6 @@ return new class extends Migration { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); diff --git a/database/migrations/2024_04_17_062223_create_teachers_table.php b/database/migrations/2024_04_17_062223_create_teachers_table.php new file mode 100644 index 0000000..1b2f14c --- /dev/null +++ b/database/migrations/2024_04_17_062223_create_teachers_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('last_name'); + $table->string('middle_name')->nullable(); + $table->date('birthday'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('teachers'); + } +}; diff --git a/database/migrations/2024_04_17_062332_create_students_table.php b/database/migrations/2024_04_17_062332_create_students_table.php new file mode 100644 index 0000000..6be03e1 --- /dev/null +++ b/database/migrations/2024_04_17_062332_create_students_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('last_name'); + $table->string('middle_name')->nullable(); + $table->date('birthday'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('students'); + } +}; diff --git a/database/migrations/2024_04_17_062412_create_admins_table.php b/database/migrations/2024_04_17_062412_create_admins_table.php new file mode 100644 index 0000000..fa97368 --- /dev/null +++ b/database/migrations/2024_04_17_062412_create_admins_table.php @@ -0,0 +1,27 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('admins'); + } +}; diff --git a/database/migrations/2024_04_17_064554_add_foreign_key_to_users.php b/database/migrations/2024_04_17_064554_add_foreign_key_to_users.php new file mode 100644 index 0000000..758992c --- /dev/null +++ b/database/migrations/2024_04_17_064554_add_foreign_key_to_users.php @@ -0,0 +1,28 @@ +foreignId('grade_id')->constrained('grades'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('grade_id'); + }); + } +}; diff --git a/database/migrations/2024_04_17_071019_create_subject_teacher_table.php b/database/migrations/2024_04_17_071019_create_subject_teacher_table.php new file mode 100644 index 0000000..76f814c --- /dev/null +++ b/database/migrations/2024_04_17_071019_create_subject_teacher_table.php @@ -0,0 +1,28 @@ +foreignId('subject_id')->constrained('subjects')->onDelete('cascade'); + $table->foreignId('teacher_id')->constrained('teachers')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subject_teacher'); + } +}; diff --git a/database/migrations/2024_04_17_071104_create_grade_teacher_table.php b/database/migrations/2024_04_17_071104_create_grade_teacher_table.php new file mode 100644 index 0000000..a7994a0 --- /dev/null +++ b/database/migrations/2024_04_17_071104_create_grade_teacher_table.php @@ -0,0 +1,28 @@ +foreignId('grade_id')->constrained('grades')->onDelete('cascade'); + $table->foreignId('teacher_id')->constrained('teachers')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('grade_teacher'); + } +};