I have multiple databases and switching database as per some conditions before dispatching jobs. For eg:
if(condition A){
DB::setDefaultConnection('A');
} else {
DB::setDefaultConnection('B');
}
dispatch(new CreateNewUser($user))
And the db connection is changed as per the condition.
As I query something like User::find($id) before dispatching the job which returns data as per the connected database.
But the problem is, the dispatch() create a jobs record in jobs table of that database which was connected at first. When the db connection changed to another, still the first database's jobs table is populated.
How is this happening?