You'll just have to add queries to check if it has relations. whereDoesntHave or something.
Sep 12, 2017
4
Level 3
How to delete a records which its ID not exists in another tables ?
Hi,
I have a table of users
Users
id, first_name, last_name
1, Tom, Baar
and also I have 10 tables where all of them have a column which is the foreign_key of user_id
e.x.
Contracts
id, name, contract_manager(foreign key of users table)
1, Servers, 1
Logs
id, data, user_id(foreign key of users table)
1, data, 1
My question is how can I check if the user_id who I want to delete exists in one of the 10 tables it is associated so that I prevent the deleteion of the user ?
Please or to participate in this conversation.