public function createReply($user, $replyFields) { $reply = new Reply($replyFields); $reply->author_id = $user->id; $reply->topic_id = $this->id; $reply->save(); return $reply; }
/** * Store a newly created resource in storage. * * @param $id * @param CreateAnswerRequest $request * @return Response */ public function store($id, CreateAnswerRequest $request) { $comment = Comment::findOrFail($id); $reply = new Reply(); $reply->fill($request->all()); $reply->user_id = Auth::user()->id; $reply->comment_id = $comment->id; $reply->save(); $messages = trans('messages.replies.create'); if ($request->ajax()) { return $messages; } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->has('body-reply')) { $request->merge(['body-reply' => $request->get('body-reply')]); } else { $name = 'body-reply-comment' . $request->entity_id; $request->merge(['body-reply' => $request->get($name)]); } // @todo form validate $this->validate($request, ['content_id' => 'required|integer', 'entity_id' => 'required|integer', 'entity_type' => 'in:content,comment|string', 'body-reply' => 'required|min:1']); $Reply = new Reply(); $Reply->user_id = Auth::user()->id; $Reply->entity_id = $request->get('entity_id'); $Reply->body = $request->get('body-reply'); // type_id if ($request->get('entity_type') === 'content') { $Reply->type_id = Reply::TYPE_CONTENT; } else { if ($request->get('entity_type') === 'comment') { $Reply->type_id = Reply::TYPE_COMMENT; } } if ($Reply->save()) { if ($request->get('entity_type') === 'content') { event(new \App\Events\ContentWasReplied($Reply)); } else { if ($request->get('entity_type') === 'comment') { event(new \App\Events\CommentWasReplied($Reply)); } } Flash::success(trans('app.Successful operation')); $route = (new Content())->getAppointRoute('show', $request->get('content_id')); return redirect()->route($route, ['id' => $request->get('content_id')]); } else { Flash::error(trans('app.Operation failed')); return redirect()->back(); } }