How to change model connection on runtime?
How to change model connection on runtime without extending eloquent method/s?
There is a method on which returns Eloquent\Builder, but then this won't work:
User::on('master')->create($data);
while this will:
User::on('master')->insert($data);
However this way model events can't be used.
You have to use User::connection('master')->insert();
Sent from my iPhone
On 06/07/2013, at 12:26, Premke [email protected] wrote:
How to change model connection on runtime without extending eloquent method/s?
There is a method on which returns Eloquent\Builder, but then this won't work:
User::on('master')->create($data); while this will:
User::on('master')->insert($data); However this way model events can't be used.
— Reply to this email directly or view it on GitHub.
The on method returns a Builder object, not a Model object. That's why the create method and model events do not work. There is a setConnection method or you could call getModel on the Builder object.
@ipalaus When using insert model events are not triggered.
@ronaldcastillo Thanks for clearing that up, I've ended up using getModel.