jeudi 27 juin 2019

Laravel: Copy models/rows from one connection to another

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?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31USziM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire