Laravel: How to delete rows from multiple table with same id with only 1 query?

后端 未结 1 1617
刺人心
刺人心 2021-01-21 08:24

I have this code to delete data from multiple tables in one go:

DB::table(\'tb_stikes_register_school\')->where(\'register_id\', $_POST[\'id\'])->delete();         


        
1条回答
  •  一生所求
    2021-01-21 08:57

    Something like this maybe - haven't tested

    DB::table(DB::raw('FROM tb_stikes_register_school, tb_stikes_register_guardian, tb_stikes_register_student'))
    ->join(ENTER JOIN INFO) // wasn't clear how your tables were related
    ->where('register_id', $_POST['id'])
    ->delete();
    

    Or you could use a fully raw query:

     DB::query('SQL statement here');
    

    Basically recreating something similar to this: delete rows from multiple tables

    0 讨论(0)
提交回复
热议问题