/** * Update the specified resource in storage. * * @param Requests\PaperRequest $request * @param Paper $paper * @return \Illuminate\Http\Response */ public function update(Requests\PaperRequest $request, Paper $paper) { $this->paper->setPaper($paper); $status = $request->get('status_id'); $reviewer = $request->get('reviewer_id') ?: null; if (!$paper->reviewer_id && $reviewer) { if ($request->get('status_id') < 2) { $status = 2; } } $department = Department::find($request->get('department_id')); $this->paper->setUrl($department->keyword); if (!in_array($request->get('category_id'), $department->categories->lists('id')->toArray())) { return redirect()->back()->with('error', 'department-category'); } if ($paper->department_id != $request->get('department_id')) { #if department is changed files must be moved $url = $this->paper->prefix(); $oldPath = $url . '/' . $paper->department->keyword . '/'; $newPath = $url . '/' . $department->keyword . '/'; File::move($oldPath . $paper->source, $newPath . $paper->source); if ($paper->payment_source) { File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source); } } $paperData = ['department_id' => $department->id, 'category_id' => $request->get('category_id'), 'status_id' => $status, 'title' => $request->get('title'), 'description' => $request->get('description'), 'authors' => $request->get('authors'), 'user_id' => $request->get('user_id'), 'reviewer_id' => $reviewer, 'updated_at' => Carbon::now(), 'payment_description' => $request->get('payment_description')]; if ($request->file('paper')) { $paperData['source'] = $this->paper->buildFileName(); $this->paper->deleteFile(); } if ($request->file('payment_source')) { $paperData['payment_source'] = $this->paper->buildInvoiceName(); $this->paper->deleteInvoice(); } $this->paper->upload(); $oldReviewer = $paper->reviewer_id; $paper->update($paperData); if ($oldReviewer != $paper->reviewer_id) { #reviewer changed event(new ReviewerPaperSet($paper)); } return redirect()->action('Admin\\PaperController@index')->with('success', 'updated'); }
/** * Update the specified resource in storage. * * @param Requests\PaperRequest $request * @param Department $department * @param Paper $paper * @return \Illuminate\Http\Response */ public function update(Requests\PaperRequest $request, Department $department, Paper $paper) { if ($paper->canEdit() && $paper->isAuthor()) { $this->paper->setPaper($paper); $paperData = ['category_id' => $request->get('category_id'), 'title' => $request->get('title'), 'description' => $request->get('description'), 'authors' => $request->get('authors'), 'updated_at' => Carbon::now()]; if ($request->file('paper')) { $paperData['source'] = $this->paper->buildFileName(); $this->paper->deleteFile(); $this->paper->upload($paperData['source']); } $paper->update($paperData); event(new PaperWasUpdated($paper)); return redirect()->action('PaperController@index', [$department->keyword])->with('success', 'paper-updated'); } return redirect()->back()->with('error', 'access-denied'); }