@ajax30 You are deleting the comment first and then you are trying to delete replies of comment which you have already deleted.
Here is the updated delete comment function function
public function delete_comment($id) {
$comment = Comment::find($id);
if($comment->user_id === auth()->user()->id) {
$comment->replies()->delete();
$comment->delete();
return redirect()->back()->with('success', 'The comment was deleted');
}
}
I assume you have already created a hasMany relationship of replies in the Comment modal.
Thanks!
ajax30 liked this reply
Please try answering this question too. Thanks!
(Link removed)
@ajax30 people can answer other questions if they have the time and know the answer. It is not wanted to ask them from one thread to answer another one.
Please consider posting an answer to this question too. Thanks!
(mention and link removed)
@ajax30 as mentioned earlier please don't ask people to answer other threads. They will see it if they have time.
If they are 100% related I can understand it but that isn't the case.
I hope this is clear to you now :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community