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

DevOps

MOTOSHARE šŸš—šŸļø
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
šŸš€ Everyone wins.

Start Your Journey with Motoshare

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 ?Code language: JavaScript (javascript)

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