i have a comment system, that users can reply others. when somebody post a comment, it does not display until admin approve it. until here there is no problem.
but when somebody reply others comment, the reply comment would display without admin permission. this is problem.
What should I do?
this is my post show controller
public function show(Post $post)
{
$count = $post->comments()->count();
$comments = $post->comments()->where('approved',true)->get();
return view('site/post/show',compact('post','comments','count'));
}
this is my comment controller
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',
'replyComment' => '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();
}
this is my comment model
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');
}
this is my post model
use Sluggable;
protected $fillable = [
'title','slug', 'body', 'views', 'category_id', 'user_id'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function categories()
{
return $this->belongsToMany(Category::class,'post_category');
}
public function tags()
{
return $this->belongsToMany(Tag::class);
}
public function comments()
{
return $this->morphMany(Comment::class,'commentable');
}
what should id do?