public function store(Request $request) { $registrar = Auth::guard('api_registration')->user(); $file = new RegistrationEquationFile(); $file->fill($request->only('type', 'registration_equation_id', 'file')); $file->save(); $attachments = $file->urlsForAttachment('file'); foreach ($attachments as $key => $attachment) { $attachments[$key] = asset($attachment); } $file->attachments = $attachments; return response()->json($file, 200, [], JSON_NUMERIC_CHECK); }
public function store(Request $request) { $equation = RegistrationEquation::findOrNew($request->input('id')); $equation->fill($request->only('university', 'level', 'grade')); $equation->registration_id = $this->user->id; $equation->save(); /** populate files and delete unused] */ $files_ids = []; foreach ($request->input('files') as $file) { if (!empty($file['id'])) { $files_ids[] = $file['id']; } } RegistrationEquationFile::whereIn('id', $files_ids)->update(['registration_equation_id' => $equation->id]); RegistrationEquationFile::whereNotIn('id', $files_ids)->where('registration_equation_id', $equation->id)->delete(); /** end populate files */ /** populate subjects */ $old_subject_ids = []; foreach ($request->input('subjects') as $subject) { if (!empty($subject['id'])) { $old_subject_ids[] = $subject['id']; } } RegistrationEquationSubject::whereNotIn('id', $old_subject_ids)->where('registration_equation_id', $equation->id)->delete(); foreach ($request->input('subjects') as $subject) { if (empty($subject['id'])) { $subject['status'] = 'waiting'; $equation->subjects()->create($subject); } else { RegistrationEquationSubject::where('id', $subject['id'])->update($subject); } } /** ned populate subjects */ $equation->load('files', 'subjects'); foreach ($equation->files as $file) { $attachments = $file->urlsForAttachment('file'); foreach ($attachments as $key => $attachment) { $attachments[$key] = asset($attachment); } $file->attachments = $attachments; } // update step and dispatch it $next_step = RegistrationStep::find($this->user->registration_step_id)->children()->where('equation_processing', 1)->first(); if ($next_step) { $this->user->registration_step_id = $next_step->id; $this->user->save(); event(new RegistrationStepChanged($this->user, ['comment' => 'تم تغييرها بشكل تلقائي بعد اضافة الطالب لشهادة'])); } // return response()->json(compact('equation'), 200, [], JSON_NUMERIC_CHECK); }