Search code examples
laravel

Laravel change job connection to a different database


How can I dispatch my jobs to SQLite and not my MySQL connection? My main connection is MySQL and I need to specify the connection because my SQLite has the correct tables. I do not want to change my DB_Connection in my env file because I need both connections.

I tried FilterBroadcastMessage::dispatch()->onConnection('sqlite'); but this "connection" is referring to the "connection" in my config/queue.php


Solution

  • This fixed my problem.

    Added the config/database.php connection to my config/queue.php database connection. And changed QUEUE_CONNECTION to database in .env file.

    'database' =>[
                  'connection' => 'sqlite',
                  'driver' => 'database',
                  'table' => 'jobs',
                  'queue' => 'default',
                  'retry_after' => 90,
                 ],