user_id
column on the
books_chapter
table references the
id 
column on a
users
table:

$table->foreign('book_id')->references('id')->on('books');
$table->foreign('chapter_id')->references('id')->on('texts');
$table->foreign('user_id')->references('id')->on('users');
->onDelete('cascade')
helps us to automatically delete related rows in Laravel

$table->foreign('book_id')->references('id')->on('books')->onDelete('cascade');
$table->foreign('chapter_id')->references('id')->on('texts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
by Luka Tatarishvili
4 years ago
Laravel
database
0
Pro tip: use ```triple backticks around text``` to write in code fences