// Clone the model into a new, non-existing instance.
$user->replicate()->setConnection('testing')->save();
I use this
I'm trying to save (as well as update) a user model into multiple databases but just can't figure out what's going wrong. This first part works fine:
$user = User::find(1);
$user->name = 'Test';
$user->save();
But what's going wrong with this bit here?
$user->setConnection('testing')->save();
Not getting any errors just nothing is stored to the "testing" database. Any ideas what needs adjusting?
Its not the right solution. You should replicate outside of Laravel.
if thats not possible, then consider using eloquent model events to fire updates to your other database. You don't want this stuff littered through your code.
Please or to participate in this conversation.