8/24/2017 - 1:42 AM

Null Cascade on Delete

Null Cascade on Delete


Let's say that we now have two tables tutorials and courses. 
One tutorial can belong to only one courses and one courses can have many tutorials.

Now the business rule: "If the courses is deleted, 
orphan the tutorials that belonged to that courses. 
What I wanted to say here is to set the course_id value to null, 
meaning that the tutorial that has previously belonged to a courses, 
now no longer belongs to any courses and is independent.

Schema::table('tutorials', function ($table) {
    // ...
          ->onDelete('set null');