Support the ongoing development of Laravel.io →
Blade Forms Laravel
Last updated by @ajax30 3 months ago.
0

@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

1
Solution selected by @ajax30

Please try answering this question too. Thanks!

(Link removed)

Last updated by @tvbeek 3 months ago.
0
moderator

@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.

Last updated by @tvbeek 3 months ago.
0

Please consider posting an answer to this question too. Thanks!

(mention and link removed)

Last updated by @tvbeek 2 months ago.
0
moderator

@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 :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Razvan ajax30 Joined 2 Oct 2021

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.