I have a model with a connection parameter to a different database.
class User extends Model
{
protected $connection = 'main_database';
}
When I save the model the connection is returning to default application connection which is named "mysql".
It only happens if one of model values is changed.
$user = User::find(1);
$user->surname = 'changed surname';
$user->save();
dd($user->getConnectionName());
Is it a laravel bug?
2
Answers
Never mind. I had this in Trackable trait and that was a problem.
It’s necessary to refresh the $user variable.