/** * This method will be creating an application row in the database and fill * it upp with the visitors information. It will also create the required * foreign key linked tables and save all of them in the database * @return view */ private function submitForm() { DB::transaction(function () { $application_form = new \App\Application_form(); $application_form->user_id = Auth::user()->id; $application_form->status = 'pending'; $application_form->date = date('Y-m-d'); $application_form->save(); $application_id = $application_form->id; foreach (Session::pull('competenceArray') as $comp) { $competence_profile = new \App\Competence_profile(); $competence_profile->application_id = $application_id; $competence_profile->competence_id = \App\Competence::where('name', $comp->competence)->value('id'); $competence_profile->years_of_experience = $comp->years; $competence_profile->save(); } foreach (Session::pull('periodArray') as $comp) { $periods = new \App\Period(); $periods->application_id = $application_id; $periods->from_date = $comp->from_date; $periods->to_date = $comp->to_date; $periods->save(); } }); return view('submit_success'); }
/** * This method will fetch all the competences and period of work for a * specific person. This person will be the person that has the application * id that is entered by the visitor. The information will then be saved * in their corresponding arrays in the session array * @param Request $request * @return view */ public function fetchData(Request $request) { $this->validate($request, ['appId' => 'required|max:2']); Session::forget('periodArray'); Session::forget('competenceArray'); Session::forget('listArray'); DB::transaction(function () { $currentId = Req::get('appId'); $competence_profile = \App\Competence_profile::where('application_id', $currentId)->get(); foreach ($competence_profile as $profile) { $competence = \App\Competence::where('id', $profile->competence_id)->value('name'); $competenceObj = new \App\CompetenceObj($competence, $profile->years_of_experience); Session::push('competenceArray', $competenceObj); } $periods = \App\Period::where('application_id', $currentId)->get(); foreach ($periods as $period) { $periodObj = new \App\PeriodObj($period->from_date, $period->to_date); Session::push('periodArray', $periodObj); } $applications = \App\Application_form::where('id', $currentId)->get(); foreach ($applications as $application) { $first_name = \App\User::where('id', $application->user_id)->value('first_name'); $last_name = \App\User::where('id', $application->user_id)->value('last_name'); $ssn = \App\User::where('id', $application->user_id)->value('ssn'); $email = \App\User::where('id', $application->user_id)->value('email'); $applicationDTO = new \App\ApplicationDTO($application->id, $first_name, $last_name, $ssn, $email, $application->date, $application->status); Session::push('listArray', $applicationDTO); } }); return view('status_application'); }