I am attempting to override the default database connection used by a model to another one which I have defined in config/database.php
.
However when bulk inserting data, the two inserts listed below work differently:
$model= new SomeModel();
$model->setConnection('another_connection');
// Throws exception due to invalid data which needs casted,
// done via setSomeFieldAttribute() methods defined in SomeModel()
$model->insert($data);
// Works, performs setSomeFieldAttribute() methods
// but inserts data on default connection
$model::insert($data);
How can I perform bulk insertion, with setAttribute()
methods on a set connection?