0

I have done the following:

<tbody style="font-family: Nunito">
  @if($users)
      @foreach($users as $user)
      <tr class="text-right">
          <th scope="row">{{$ids[$user->id]}}</th>
          <td>{{$user->name}}</td>
          <td>{{$user->email}}</td>
          <td>{{$user->role->name}}</td>
          <td>{{$dates[$user->id]}}</td>
          <td class="text-left">
            <a class="btn btn-sm btn-danger px-4" style="font-family: myFirstFont" href="{{route('users.destroy', $user->id)}}">Delet</a>
          </td>
      </tr>
      @endforeach
  @endif
</tbody>

When I change the parameter inside route to 'users.edit', the code inside the edit method in the controller runs.

but when I write 'users.destroy', the code inside destroy method does not run.

It does not give any error.

2
  • check the route declared for the method [laravel.com/docs/8.x/routing] Commented Aug 3, 2021 at 10:14
  • laravel resource defines 'users.destroy' as DELETE method but you are using get method. You should use <form action="{{ route(users.destroy)}}" method="POST"> @method('DELETE') @csrf </form> Commented Aug 3, 2021 at 10:20

1 Answer 1

2

Try this

<form action="{{ route('users.destroy',$user->id) }}" method="POST">   
    @csrf
    @method('DELETE')
      
    <button type="submit" class="btn btn-danger">Delete</button>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.