tgugnani shares a good tip on how to delete data that belongs to one-to-many relationship in Laravel.

laravel 5 tips

In this tutorial let’s dig into how we can gracefully delete data that belongs to one to many relationship in Laravel.

For this let’s consider an example of a relationship between Category and Post. Category can have many posts.

If you delete the category without handling the associated posts then it will cause problems in the application, since you have post data in your database which is still associated with a category that does not exist.