How to Delete Data in Multiple Tables (with Relationship) Laravel.

To delete data from the database with a relationship with two tables in Laravel we have to use the solution that I’ve used.

Now, Question is Where and when we use this Method ?

Let’s Discuss, what problems I faced and how Solved it.

In my project, I’ve two Tables in the Database 1st is my Users table where users’ data is stored. 

See the below image:-

And 2nd is SocialProviders where the user’s Provider ID is stored (whenever a user login with Google, Facebook, etc then a unique provider_id is stored to verify the users ) with the user_id to find which provider is for which user. 

See the below image:-

and whenever I Delete a user then I have to delete User data from both the Users table and SocialProviders table for that user.

Now, My problem is that I am not able to delete the User data from the SocialProviders table but the user’s table data is deleted, and when the user re-login with the same Email ID then an error occurs.

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x