samedi 21 mai 2016

Bulk Insert instead of foreach loop: Laravel 5.2.31

I am using the following code to insert the records One by One.

foreach($data["SportsTypes"] as $SportsTypeID) {
    $userSportsType = new \App\Models\User\UserSportsTypeModel();
    $userSportsType->UserID       = 1;
    $userSportsType->SportsTypeID = $SportsTypeID;
    $userSportsType->save();
}

Can I do bulk insert so as to get rid of saving process in iteration?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire