I want to copy an eloquent model from one connection to another.
The way I have done this so far is as so:
$users = User::on('connection1')->where('tenant', 'foo')->get();
User::on('connection2')->insert($users->toArray());
This works most of the time. But there are cases where this does not work. For example:
- When the model has
$hidden
attribute - When the
toArray
method for a model is overrided
What is a reliable way to simply copy over some rows to another connection?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire