I ran into this issue too. The only way I could figure to do it was to create another database connection entry in my database.php config file.
'mysql' => array(
'driver' => 'mysql',
'read' => array(
'host' => 'read-host',
'database' => 'read-database',
'username' => 'read-username',
'password' => 'read-password',
),
'write' => array(
'host' => 'write-host',
'database' => 'write-database',
'username' => 'write-username',
'password' => 'write-password',
),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'mysql-write' => array(
'driver' => 'mysql',
'host' => 'write-host',
'database' => 'write-database',
'username' => 'write-username',
'password' => 'write-password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Then when you need to force a select using the write connection, you can do this:
DB::connection('mysql-write')->select(...);
Or if you are using Eloquent:
User::on('mysql-write')->find(1);
See: http://laravel.com/api/5.1/Illuminate/Database/Eloquent/Model.html#method_onWriteConnection
It allows you to query the model on the write connection.
Example use:
User::onWriteConnection()->find(1);
$r = DB::connection($this->connection)
->selectFromWriteConnection("CALL maker_create_service_order(?, ?, ?, ?, ?, ?);",[
$creationId, $accountId, $storeId, $storeProductId, $quantity, $total
]);
This works fine for me.
Is this working in laravel 5.3 tried to do so by its seems that its not working
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community