Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.
Moderator: General Moderators
-
gautamz07
- Forum Contributor
- Posts: 331
- Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 »
I was going through this section in the laravel documentation:
https://laravel.com/docs/5.4/migrations ... onstraints
I saw the below line of code:
Code: Select all
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
I am not quite understanding the onDelete part , can somebody please explain that to me ?
Thank you.
Gautam.
-
Celauran
- Moderator
- Posts: 6425
- Joined: Tue Nov 09, 2010 2:39 pm
- Location: Montreal, Canada
Post
by Celauran »
You have a user model. Comments belong to a user. With cascading deletes, deleting a user would also delete all their comments.
-
gautamz07
- Forum Contributor
- Posts: 331
- Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 »
Thanks got it !
