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

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

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.

Subscribe
Notify of
guest

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

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x