mardi 30 août 2016

Delete user and user created data in Laravel 5

I have a site where users can create posts and messages. I want it so that when a user delete's their profile, that all user's posts and messages will be deleted as well. I have a users, messages, and posts table. I was thinking of just doing something like

User::destroy(Auth->user()->id); //to delete user
Message::where(user_id, Auth->user())->delete(); //to delete al messages from that user
Post::where(user_id, Auth->user())->delete(); //to delete all posts from that user

Is this the best way, or is there a more elegant option? Do i need to basically search all my tables for that user_id then delete each row?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bzxh23
via IFTTT

Aucun commentaire:

Enregistrer un commentaire