Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tangaye's avatar

PUT won't work, but POST does instead

I trying to update records in my table, and following the laravel's documentation I learned that such a request should be a PUT request.

Route:

Route::put('/students/update/{id}', 'StudentsController@update');

Controller:

public function update(Request $request, $id)
{
    //
    // make validation
    $rules = [
        'surname' => 'bail|required|max:50|min:1|regex:/^[a-z ,.\'-]+$/i'
    ];

    $validator = Validator::make($request->all(), $rules);

    if ($validator->fails ()) {
        return back()->withInput();
    } else {
        // find student
        $student = Student::findOrFail($id);

        //update student record
        $student->update(request([
            'surname'
        ]));

        // send a message to the session that greets/ thank user
        session()->flash('message', $student->first_name." ".$student->surname);

        return redirect('/students');
    }
}

form:

<form method="put" action="/students/update/{{$student->id}}">

    {{csrf_field()}}
   <input type="hidden" name="_method" value="PUT">

    <input type="text" name="surname">
</form>

This is throw this error:

MethodNotAllowedHttpException

route list:

+--------+----------+-----------------------+------+--------------------------------------------------+--------------+
| Domain | Method   | URI                   | Name | Action                                           | Middleware   |
+--------+----------+-----------------------+------+--------------------------------------------------+--------------+
|        | GET|HEAD | /                     |      | Closure                                          | web          |
|        | GET|HEAD | api/user              |      | Closure                                          | api,auth:api |
|        | GET|HEAD | divisions             |      | App\Http\Controllers\DivisionsController@index   | web          |
|        | POST     | divisions             |      | App\Http\Controllers\DivisionsController@store   | web          |
|        | DELETE   | divisions/delete/{id} |      | App\Http\Controllers\DivisionsController@destroy | web          |
|        | PUT      | divisions/update/{id} |      | App\Http\Controllers\DivisionsController@update  | web          |
|        | POST     | grades                |      | App\Http\Controllers\GradesController@store      | web          |
|        | GET|HEAD | grades                |      | App\Http\Controllers\GradesController@index      | web          |
|        | DELETE   | grades/delete/{id}    |      | App\Http\Controllers\GradesController@destroy    | web          |
|        | GET|HEAD | grades/edit/{id}      |      | App\Http\Controllers\GradesController@edit       | web          |
|        | PUT      | grades/update/{id}    |      | App\Http\Controllers\GradesController@update     | web          |
|        | GET|HEAD | students              |      | App\Http\Controllers\StudentsController@index    | web          |
|        | POST     | students              |      | App\Http\Controllers\StudentsController@store    | web          |
|        | GET|HEAD | students/create       |      | App\Http\Controllers\StudentsController@create   | web          |
|        | PUT      | students/update/{id}  |      | App\Http\Controllers\StudentsController@update   | web          |
|        | DELETE   | students/{id}/delete  |      | App\Http\Controllers\StudentsController@destroy  | web          |
|        | GET|HEAD | students/{id}/edit    |      | App\Http\Controllers\StudentsController@edit     | web          |
|        | POST     | subjects              |      | App\Http\Controllers\SubjectsController@store    | web          |
|        | GET|HEAD | subjects              |      | App\Http\Controllers\SubjectsController@index    | web          |
|        | DELETE   | subjects/delete/{id}  |      | App\Http\Controllers\SubjectsController@destroy  | web          |
|        | GET|HEAD | subjects/edit/{id}    |      | App\Http\Controllers\SubjectsController@edit     | web          |
|        | PUT      | subjects/update/{id}  |      | App\Http\Controllers\SubjectsController@update   | web          |
+--------+----------+-----------------------+------+--------------------------------------------------+--------------+

What am I getting wrong here?

0 likes
4 replies
martinbean's avatar
Level 80

@Tangaye Most web browsers only support the GET and POST methods for HTML forms.

Instead, you’ll need to send a POST request, but also send a hidden input called `_meth (note the underscore) with a value of “PUT”:

<form action="{{ route('student.update', $student) }}" method="POST">
    <input type="hidden" name="_method" value="PUT" />
    <input type="hidden" name="_token" value="{{ csrf_token() }}" />

    <!-- Your other form fields -->
</form>

Laravel will treat this as a PUT request and not a POST request then.

1 like
Tangaye's avatar

@martinbean thanks. My route remain put and I follow as you suggested which got it working.

martinbean's avatar

@Tangaye No. All you need to do is change the method attribute on your <form> tag to be POST, and then include the hidden input that tells Laravel it should be treated as a PUT request instead.

1 like
tykus's avatar

@tangaye your route should remain as PUT - Laravel will see the _method field and understand that the request method should be PUT

1 like

Please or to participate in this conversation.