post method not supported laravel; We have solved when we are updating user data then got this error “The POST method is not supported for this route in laravel. Supported methods: GET, HEAD, PUT, PATCH, DELETE.” in laravel.
I have searched in google but not getting any best solution so I try a best way and fixed the post method issue easily.
Solution:
So, fixing this issue you just need to add @method(‘put’) inside in form just like below.
<form action="{{ route('users.update',$user->id) }}" method="post">
@method('put')
@csrf
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" value="{{ old('name', $user->name) }}" class="form-control" placeholder="name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Email:</strong>
<input type="text" name="email" value="{{ old('email', $user->email) }}" class="form-control" placeholder="email">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
If you are using PUT you can change the form action to POST and add a hidden method_field that has a value PUTand a hidden csrf field (if you are using blade then you just need to add @csrf_field and {{ method_field(‘PUT’) }}). This way the form would accept the request.
Hurrah! 😀 The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. issue fixed easily in laravel when updating form.