lily90
1 week ago

How do I delete row in many to many relationship in view.blade?

Posted 1 week ago by lily90

I create 3 table which are user event and event_user. How do I put call in my view.blade?

  public function destroy($id)
    {
        $event= Event::find($id);
        $user->event()->detach($event);
        return view('user.event.applied');
    }
  @foreach ($events as $event)
                               
                                        <tr>
                                            <td>{{$loop->index +1 }}</td>
                                            <td>{{$event->event_name}}</td>
                                            <td>{{$event->event_date}}</td>
                                            <td>
                                              <form method="POST" action="{{ route('user.event.destroy',$event)}}">
                                                @csrf 
                                                @method('DELETE')
                                                <a class="btn btn-danger">Unjoined!</a> 
                                            </form>
                                            </td>
                                        </tr>
                                  @endforeach

Please sign in or create an account to participate in this conversation.