Reputation: 534
I have 2 database connections defined:
and the 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 this doesn't work:
$persons = BoPerson::on('sqlite')->all();
How to switch from my default 'mysql' connection to the one named 'sqlite'?
Upvotes: 2
Views: 4876
Reputation: 5791
All()
is a static function.
In this case, use get()
:
$persons = BoPerson::on('sqlite')->get();
Source: http://laravel.com/docs/4.2/eloquent#basic-usage
Upvotes: 1