What does onDelete('cascade') mean?

后端 未结 4 1277
说谎
说谎 2021-02-02 10:00
Schema::table(\'posts\', function (Blueprint $table) {
    $table->integer(\'user_id\')->unsigned();
    $table->foreign(\'user_id\')->references(\'id\')->         


        
4条回答
  •  梦毁少年i
    2021-02-02 10:53

    The code you are talking about creates a foreign key / reference to a column on another table. The onDelete('cascade') means that when the row is deleted, it will delete all it's references and attached data too.

    For example if you have a User which has a Post and you set onDelete('cascade') on the user, then when the user deletes his account, all posts will be deleted as well.

    You can find more information on Laravel excellent documentation.

提交回复
热议问题