How do I optimize these queries to be one or two? The one in the loop to be one at least.
$applicantIds = \DB::select()->from( 'applicants' )->where( 'created_at', 0 )->execute();
foreach ($applicantIds as $applicantId)
{
$applicantApp = \DB::select( 'applicant_id', 'created_at' )->from( 'applicant_apps' )->where( 'applicant_id', $applicantId['id'] )->execute();
\DB::update( 'applicants' )->value( 'created_at', $applicantApp[0]['created_at'] )->where( 'id', $applicantApp[0]['applicant_id'] )->execute();
}
I I understand you, you can use singe query for this:
When you want to use Laravel syntax:
Online test