public function addDocument(Application $application, Request $request) { if ($application->user->id != Auth::user()->id && !Auth::user()->can('add-files')) { $request->session()->flash('error', 'Only the person who created an application may answer questions for it.'); return redirect('/login'); } // Save uploaded file $upload = Document::handleUpload($request); // Save new document Document::createDocument($application, $upload, null); $request->session()->flash('success', 'Your file has been added.'); return redirect()->back(); }
public function updateAnswer(AnswerRequest $request, Answer $answer) { $input = $request->all(); $application = Application::find($input['application_id']); if ($answer->user->id != Auth::user()->id) { $request->session()->flash('error', 'Only the person who created an application may answer questions for it.'); return redirect('/login'); } if ($answer->application->status != 'new') { $request->session()->flash('error', 'Your application has been submitted, you may no longer make changes.'); return redirect('/applications/' . $application->id . '/review'); } $answer->update($input); // Check if a file needs to be uploaded if ($answer->question->type == 'file') { // Save uploaded file $upload = Document::handleUpload($request); // Save new document Document::createDocument($application, $upload, $answer); } $request->session()->flash('success', 'Your answer has been saved.'); return redirect('/applications/' . $answer->application->id); }