/** * @api {post} /tasks/:slug/posts Create A Post * @apiGroup Task Posts * @apiDescription Add a post (tip/question) on a task. For submissions use the "Add A Task Submission" endpoint * and a post will be generated. * * @param Request $request * @param Task $task * * @return \Illuminate\Http\Response */ public function store(Request $request, Task $task) { $this->requireAuthentication(); $this->validate($request, ['title' => 'required', 'text' => 'string', 'image' => '', 'type' => 'in:question,tip']); $post = new Post(['taskId' => $task->id, 'userId' => $this->user->id, 'title' => $request->input('title'), 'text' => $request->input('text'), 'type' => $request->input('type')]); $post->save(); $post = $post->fresh(); return $this->response(['post' => $post]); }