Wednesday, March 15, 2017

How many connections do Laravel Eloquent model operation create?

As far as I understand, each DB:: object in Laravel opens new connection and closes it when the operation is finished.

But what with models, especially when I make some changes to them?

For example, if I have

$users = User::all();
foreach($users as $user) {
    $user->setVisible(['id', 'name']);
    // some more operations with data happen here
}

I don't do any save() or update() to these models, just read the data in foreach, setting custom visible columns.

How many connections will be created and closed during this process?



via Yawning Milk

Advertisement