我可以在laravel中为模型方法指定不同的mysql连接吗?

I know we can specify a mysql connection for a particular model by setting

protected $connection = 'my_db';

But is there a way to specify a different connection than what the model is using for a specific method.

For example if my model is using my_db as default connection, but I want model method foo() to use a different connection my_db1. How do I do it?

Eloquent uses Query Builder under the hood, so you can try to use connection() in model method:

return $this->connection('foo')->where('id', 1)->get();

You can use DB::connection($connName).

Look in the documentation https://laravel.com/docs/5.3/database