I was wondering what's the best way to destroy mutiples database entries with ELOQUENT and I don't find a way to determine that.
So I have 3 array of id's (2 with ints, 1 with strings). Is it better to go with a foreach and ->delete() every entry or destroy the array ?
When I lookt at the destroy function, it states the following :
// We will actually pull the models from the database table and call 
delete on
// each of them individually so that their events get fired properly 
with a
// correct set of attributes in case the developers wants to check 
these.
And the code clearly shows :
$key = $instance->getKeyName();
foreach ($instance->whereIn($key, $ids)->get() as $model) {
    if ($model->delete()) {
        $count++;
    }
}
So I guess there's no real difference and the destroy function is just to avoir the use of a foreach. Can anyone confirm or inform and explain ?
Thanks :)
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire