To delete multiple records at once using Eloquent in Laravel, you can make use of the whereIn
method along with the delete
method. Here's an example:
$ids = [1, 2, 3, 4]; // IDs of records to be deleted
Model::whereIn('id', $ids)->delete();
In the above example, Model
is the name of your Eloquent model representing the table you want to delete records from. Replace Model
with the actual name of your model.
The whereIn
method is used to specify the column and the values to check for. In this case, we are checking the id
column for the values present in the $ids
array.
The delete
method is called to actually delete the matching records from the database.
You can adjust the column and values according to your specific requirements.