laravel评论回复存储不起作用

时间:2018-07-16 14:20:46

标签: laravel comments

我正在创建带有回复的评论系统,但是我在回复存储区中遇到问题。 它不起作用,并显示任何错误! 我不知道该怎么办!? 我有多态关系

评论控制器

 public function store(Request $request,Post $post)
{
    $this->validate($request,[
        'website' => 'nullable|active_url',
        'comment' => 'required|min:5'
    ]);

    $comment = new Comment();
    $comment->user_id = Auth::user()->id;
    $comment->name = Auth::user()->fname;
    $comment->email = Auth::user()->email;
    $comment->website = $request->website;
    $comment->body = $request->comment;

    $post->comments()->save($comment);
    Session::flash('success', 'Comment Send Successfully');

    return back();
}

public function reply(Request $request,Comment $comment)
{
    $this->validate($request,[
        'website' => 'nullable|active_url',
        'commentReply' => 'required|min:5'
    ]);

    $reply = new Comment();
    $reply->user_id = Auth::user()->id;
    $reply->name = Auth::user()->fname;
    $reply->email = Auth::user()->email;
    $reply->website = $request->website;
    $reply->body = $request->replyComment;

    $comment->comments()->save($reply);
    Session::flash('success', 'Comment Replyed Successfully');

    return back();
}

评论模型

 protected $fillable = [
    'parent_id', 'user_id', 'post_id', 'name', 'email', 'website', 'body', 'approved'
];

public function user()
{
    return $this->belongsTo(User::class);
}

public function post()
{
    return $this->belongsTo(Post::class);
}

public function commentable()
{
    return $this->morphTo();
}

public function comments()
{
    return $this->morphMany(Comment::class,'commentable');
}

这是我的路线

/* comment */
Route::post('/post/{post}/comment','CommentController@store')->name('comment.store');
Route::post('/comment/reply/{comment}','CommentController@reply')->name('comment.reply');

我没有评论存储问题,问题是回复不存储。 这是问题! :)

0 个答案:

没有答案