I have two tables in which I want to delete certain fields from a table related to another
a table is called procesess and another diligences and I want to eliminate all the fields that have in status_diligence the values of: pending, rejected, sent there is another value that is approved but the fields with that value must remain
I have tried this but it does not work or it deletes all those with that id even if it has the value of approved
attempt1
$diligences = Diligence::where('process_id', "=", $id)->delete([
['status_diligence', "=", "pendiente"],
['status_diligence', "=", "rechazado"],
['status_diligence', "=", "enviado"]
]);
attempt 2
$diligences = Diligence::select('process_id', $id)
->where(function($q) {
$q->where('status_diligence', 'pendiente')
->where('status_diligence', 'rechazado')
->where('status_diligence', 'enviado');
})
->delete();
Since you want to remove from the entity
Diligence
based on value matching criteria then you can make use of thewhereIn
.The above method will ask you:
So your query could look like this:
Now if apart from this filter you need to add the foreign key that is:
process_id
you will only have to chain a methodwhere
between itwhereIn
anddelete
in this way:Code: