4jean / lav_sms

Laravel School Management System (LAVSMS)
MIT License
769 stars 475 forks source link

Student delete issue #45

Closed kkfalah closed 2 years ago

kkfalah commented 2 years ago

When a student is deleted, it gets deleted from only users table, remains in students record table, that bring an error in page after deleting a student. I have fixed that issue in my local setup by adding delete line in destroy function.

kkfalah commented 2 years ago

Also when a class is deleted, the default section created automatically for that class is not getting deleted, it remains in section table.

4jean commented 2 years ago

If Migrations was successful, you wouldn't have this issue. Please ensure that your foreign key relations are set properly in your db as defined in https://github.com/4jean/lav_sms/blob/master/database/migrations/2019_09_22_142514_create_fks.php

Line 38 (ON DELETE CASCADE - user_id ) for Student Records

 Schema::table('student_records', function (Blueprint $table) {
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
               ...
        });

Line 28 (ON DELETE CASCADE - my_class_id) for Sections

Schema::table('sections', function (Blueprint $table) {
            $table->foreign('my_class_id')->references('id')->on('my_classes')->onDelete('cascade');
           ...
        });

I tested both instances on my end and it works fine. If a class is deleted, then the sections of that class including the default section would be deleted. Same goes for users

Underlying code for Class Delete is as simple as this below Line 38 @ https://github.com/4jean/lav_sms/blob/master/app/Repositories/MyClassRepo.php

public function delete($id)
    {
        return MyClass::destroy($id);
    }