2 years ago

Laravel - Delete user with anchor tag

Posted 2 years ago by Rainieren

Hello, I'm trying to make a function that deletes a user and all their content that they've posted on the website. I want to use an anchor tag for this. Currently, my code looks like this

<td class="text-center">
      <a href="{{ route('deleteUser', ['id' => $user->id]) }}" class="mr-3">
       {{ method_field('DELETE') }}
         <i class="fa fa-trash-o fa-font-24" style="color: red;"></i>
     <a href="{{ route('editUsers', ['id' => $user->id]) }}">
         <i class="fa fa-edit fa-font-24" style="color: limegreen;"></i>

The update anchor tag works just fine but the delete button gives me an error which is:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

I've put a 'dd' in the controller but it does not reach that. What is going on? Can I even use an anchor tag for this?

The route I use looks like this:

Route::delete('/adminpanel/gebruikers/delete/{id}', '[email protected]')->name('deleteUser');

And the controller looks like this:

public function deleteUser($id)
        $user = User::find($id);



        return back()->with('flash', $user->firstname, '`s account is verwijderd.');

Thanks in advance!

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