Laravel using different connections for Inserting & Selecting data

connection, laravel

Solution

This is possible with Laravel 4.1. You can configure it in your `app/config/database.php` like so:

'mysql' => array(
    'read' => array(
        'host' => '192.168.1.1',
    ),
    'write' => array(
        'host' => '196.168.1.2'
    ),
    'driver'    => 'mysql',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

See the Read / Write Connections section in the Laravel database documentation.

Problem

Is there anyway in the Laravel Eloquent to use two different connections, for inserting, updating and Selecting. What i am trying to do is specify a connection when user is pulling the data from db, and another one while inserting or updating data. I am wondering if it can be done with the Eloquent instead of defining connections everytime?

Original source

Related problems