I need to trigger a laravel job within the transaction.
Since the jobs are asynchronous, sometimes they complete before the transaction commits. In such situations, the job cannot get the relevant raw using the id. (Because the transaction is not yet committed and changes are not visible to the outside)
Please suggest a method other than putting this part outside of the transaction to solve this problem.
DB::beginTransaction()
...
$process = DB::table("trn_users")->insertGetId([
"first_name" => $first_name,
"last_name" => $last_name
]);
$job = (new SendEmailJob([
'Table' => 'trn_users',
'Id' => $process
]))->onQueue('email_send_job');
$this->dispatch($job);
...
DB:commit()