mardi 20 août 2019

Issue in using multiple databases in laravel 5.2

I have developed a project using Laravel 5.2 and I used 2 MySQL connections and configured as given below in config.database.php.

'mysql1' => [
            'driver' => 'mysql',
            'host' => 'localhost',
            'port' => '3306',
            'database' => 'main_data',
            'username' => 'root',
            'password' => 'root',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],
        'mysql2' => [
            'driver' => 'mysql',
            'host' => 'localhost',
            'port' => '3306',
            'database' => 'second',
            'username' => 'root',
            'password' => 'root',
            'charset' => 'utf8_table',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

And the model that I want to use second database connection is given below.

class package extends Eloquent {

    //use HybridRelations;
    protected $connection = 'mysql2';
    protected $table = 'PACKAGE';
...

But when I tried to create a new package in controller using package::create(data). it gives error Base table or view not found: 1146 Table 'main_data.package' doesn't exist' in ...

It seems the model connected to the default connection and when I search the only solution I could found is add protected $connection = 'mysql2'; which I already did.

Please help me to solve this issue.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31UCRUb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire