Laravel / Eloquent : change connection and get all -
i have 2 database connections defined:
- sqlite: connection specific sqlite db,
- mysql: classic mysql db.
and following model class:
class boperson extends \illuminate\database\eloquent\model { protected $table = 'persons'; protected $connection = 'mysql'; public $timestamps = false; } this works:
$persons = boperson::all(); but doesn't work:
$persons = boperson::on('sqlite')->all(); how switch default 'mysql' connection 1 named 'sqlite'?
all() static function.
in case, use get():
$persons = boperson::on('sqlite')->get();
Comments
Post a Comment