public function transform(TopicCover $cover = null) { if ($cover === null) { $cover = new TopicCover(); } if ($cover->id === null) { $data = ['method' => 'post', 'url' => route('forum.topic-covers.store', ['topic_id' => $cover->topic_id])]; } else { $data = ['method' => 'put', 'url' => route('forum.topic-covers.update', [$cover, 'topic_id' => $cover->topic_id]), 'id' => $cover->id, 'fileUrl' => $cover->fileUrl()]; } $data['dimensions'] = $cover->maxDimensions; return $data; }
public function store(HttpRequest $request, $forum_id) { $this->validate($request, ['title' => 'required', 'body' => 'required']); $forum = Forum::findOrFail($forum_id); $this->authorizePost($forum, null); $topic = Topic::createNew(['forum' => $forum, 'title' => $request->input('title'), 'poster' => Auth::user(), 'body' => $request->input('body'), 'notifyReplies' => false, 'cover' => TopicCover::findForUse(presence($request->input('cover_id')), Auth::user())]); Event::fire(new TopicWasCreated($topic, $topic->posts->last(), Auth::user())); return ujs_redirect(route('forum.topics.show', $topic)); }
public function update($id) { $cover = TopicCover::findOrFail($id); priv_check('ForumTopicCoverEdit', $cover)->ensureCan(); if (Request::hasFile('cover_file') === true) { try { $cover = $cover->updateFile(Request::file('cover_file')->getRealPath(), Auth::user()); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } } return json_item($cover, new TopicCoverTransformer()); }
public function update($id) { $cover = TopicCover::findOrFail($id); if ($cover->canBeEditedBy(Auth::user()) === false) { abort(403); } if (Request::hasFile('cover_file') === true) { try { $cover = $cover->updateFile(Request::file('cover_file')->getRealPath(), Auth::user()); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } } return fractal_item_array($cover, new TopicCoverTransformer()); }
public function store(HttpRequest $request) { $forum = Forum::findOrFail($request->get('forum_id')); priv_check('ForumTopicStore', $forum)->ensureCan(); $this->validate($request, ['title' => 'required', 'body' => 'required']); if (get_bool($request->get('with_poll'))) { $pollParams = get_params($request, 'forum_topic_poll', ['length_days:int', 'max_options:int', 'options:string_split', 'title', 'vote_change:bool']); $poll = (new TopicPoll())->fill($pollParams); if (!$poll->isValid()) { return error_popup(implode(' ', $poll->validationErrors()->allMessages())); } } $params = ['title' => $request->get('title'), 'user' => Auth::user(), 'body' => $request->get('body'), 'cover' => TopicCover::findForUse(presence($request->input('cover_id')), Auth::user())]; $topic = Topic::createNew($forum, $params, $poll ?? null); if ($topic->topic_id !== null) { Event::fire(new TopicWasCreated($topic, $topic->posts->last(), Auth::user())); return ujs_redirect(route('forum.topics.show', $topic)); } else { abort(422); } }
public function setCover($path, $user) { if ($this->cover === null) { TopicCover::upload($path, $user, $this); } else { $this->cover->storeFile($path); $this->cover->user()->associate($user); $this->cover->save(); } return $this->fresh(); }