0

Am trying to make functionality where user deletes his/her account using laravel and i am getting the error "The GET method is not supported for this route. Supported methods: PUT."...i dont know what i am doing wrong...

below is my function in UserController

public function del()
{
    $user = \User::find(Auth::user()->id);
    Auth::logout();
    if ($user->delete()) {
        return Redirect::route('welcome');
    }
}

In blade file

@extends('layouts.app')
@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <form method="put" action="wipe">
                @csrf
                <button type="submit" class="btn btn-danger">Dalete Account</button>
            </form>
        </div>
    </div>
</div>
<br/>
@include('footer')
@endsection

My route in web.php looks as follows

Route::put('users/wipe', 'UserController@del')->name('users.wipe');

I will appreciate any help...thanks in advance

Peppermintology
  • 9,343
  • 3
  • 27
  • 51
Daniel
  • 67
  • 7

1 Answers1

1

You cannot use PUT in the form method attribute: use "post" and the blade directive @method

<form method="post" action="wipe">
@method('PUT')

However to delete a user, maybe the DELETE method is a better option? (implement the same way as the PUT method)

Gert B.
  • 2,282
  • 18
  • 21