App\Repositories\CommentRepository::store PHP Method

store() public method

Store a new comment.
public store ( $input )
$input
    public function store($input)
    {
        $comment = new $this->model();
        $parse = new Parsedown();
        $comment->post_id = $input['post_id'];
        $comment->parent_id = $input['parent'];
        // Get parent comment name.
        if ($input['parent'] != 0) {
            $comment->parent_name = $this->getById($input['parent'])->name;
        }
        $comment->name = $input['name'];
        $comment->email = $input['email'];
        $comment->blog = $input['blog'];
        $comment->origin = $input['origin'];
        $comment->content = $parse->parse($input['origin']);
        $comment->save();
        // add on comment_count
        $post = $this->post->find($input['post_id']);
        $post->comment_count++;
        $post->save();
    }

Usage Example

Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  App\requests\CommentRequest $request
  * @return Response
  */
 public function store(CommentRequest $request)
 {
     $this->comment_gestion->store($request->all(), $request->user()->id);
     if ($request->user()->valid) {
         return redirect()->back();
     }
     return redirect()->back()->with('warning', trans('front/blog.warning'));
 }
All Usage Examples Of App\Repositories\CommentRepository::store