'associatedVacancyID'=>$vacancy->first()->id,// Since a form can be used by multiple vacancies, we can only know which specific vacancy this response ties to by using a vacancy ID
'responseData'=>json_encode($responseStructure)
]);
Log::info('Registered form response for user '.Auth::user()->name.' for vacancy '.$vacancy->first()->vacancyName);
Application::create([
'applicantUserID'=>Auth::user()->id,
'applicantFormResponseID'=>$response->id,
'applicationStatus'=>'STAGE_SUBMITTED',
]);
Log::info('Submitted application for user '.Auth::user()->name.' with response ID'.$response->id);
$request->session()->flash('success','Thank you for your application! It will be reviewed as soon as possible.');
returnredirect()->to(route('userPendingApps'));
}
else
{
Log::warning('Application form for '.Auth::user()->name.' contained errors, resetting!');
$request->session()->flash('error','There are one or more errors in your application. Please make sure none of your fields are empty, since they are all required.');