/** * a topic can only be restored by * the moderator of the section and destination section * * @return bool */ public function authorize() { $return = false; $currentUserID = \Auth::user()->id; $trashedTopic = \Nexus\Topic::onlyTrashed()->findOrFail($this->topic); $originalSection = \Nexus\Section::withTrashed()->findOrFail($trashedTopic->section_id); $destinationSection = \Nexus\Section::findOrFail($this->destination); if ($destinationSection->moderator->id === $currentUserID && $originalSection->moderator->id === $currentUserID) { $return = true; } else { $return = false; } return $return; }
public function getTrashedTopicsAttribute() { /* @todo: why does the hasManyThrough not work here? return $this->hasManyThrough('Nexus\Topic', 'Nexus\Section', 'user_id', 'section_id'); */ $sectionIDs = $this->sections->pluck('id')->toArray(); $trashedTopics = Topic::onlyTrashed()->whereIn('section_id', $sectionIDs)->get(); return $trashedTopics; }
public function topic(Requests\topic\RestoreRequest $request, $id) { $trashedTopic = \Nexus\Topic::onlyTrashed()->findOrFail($id); $destinationSection = \Nexus\Section::findOrFail($request->destination); \Nexus\Helpers\RestoreHelper::restoreTopicToSection($trashedTopic, $destinationSection); $redirect = action('Nexus\\SectionController@show', ['id' => $destinationSection->id]); return redirect($redirect); }