search

Home  >  Q&A  >  body text

laravel queue usage problem: multi-database configuration

Using asynchronous queue, when configuring the database, I have two databases mysql and mysql2 in config/database.php:

        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            ...
        ],

        'mysql2' => [
            'driver'    => 'mysql',
            'host'      => env('DB_O2O_HOST', 'localhost'),
            'database'  => env('DB_O2O_DATABASE', 'forge'),
            ...
        ],

I put the jobs table of the queue in mysql2. When adding tasks to the queue, the default connection is mysql. Can this be configured? ##config/queue.php To specify the connected database?

阿神阿神2825 days ago561

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 16:51:08

    In the modelconstructor of the table, show the call

       public function __construct() {
            $this->setConnection('mysql2');
            parent::__construct();
        }

    reply
    0
  • Cancelreply