Home » Php » php – Erro message stating: "The GET method is not supported for this route. Supported methods: POST" using Laravel on updating

php – Erro message stating: "The GET method is not supported for this route. Supported methods: POST" using Laravel on updating

Posted by: admin February 25, 2020 Leave a comment

Questions:

I was trying to get the value of the form data by pressing the submit button from blade, to route having a route name patient/update. I’m trying to test the $request object on controller using var_dump(). However there was an error message

“The GET method is not supported for this route”.

I tried switching from get to post. But still I cant figure out what’s the error behind.

Here is my code on blade;

<form class="" action="{{ route('patient/update') }}" metdod="post">
    @csrf
    <nav class="nav">
        <a href="{{ route('home') }}">
            <button class="btn btn-secondary mr-2 mb-2" type="button" name="button">Home</button>
        </a>
        <input type="submit" class="btn btn-primary mb-2" name="save" value="Save">
    </nav>
    <table class="table">
        <tr>
            <td>
                <label class="text-primary">Fullname</label>
                <input class="form-control" type="text" name="fullname" value="{{ $patient->fullname }}" />
            </td>
            <td>
                <label class="text-primary">Date of birth</label>
                <input class="form-control" type="date" name="date_of_birth" value="{{ $patient->date_of_birth }}" />
            </td>
            <td>
                <label class="text-primary">Sex</label>
                <input class="form-control" type="text" name="sex" value="{{ $patient->sex }}" />
            </td>
            <td>
                <label class="text-primary">Birth weight</label>
                <input class="form-control" type="text" name="birth_weight" value="{{ $patient->birth_weight }}" />
            </td>
            <td>
                <label class="text-primary">Birth length</label>
                <input class="form-control" type="text" name="birth_length" value="{{ $patient->birth_length }}" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label class="text-primary">Birth History</label>
                <textarea class="form-control" name="birth_history" rows="3" cols="30">{{ $patient->history }}</textarea>
            </td>
            <td colspan="2">
                <label class="text-primary">Feeding: </label>
                <textarea class="form-control" name="feeding" rows="3" cols="30">{{ $patient->feeding }}</textarea>
            </td>
            <td colspan="2">
                <label class="text-primary">screening_date: </label>
                <input class="form-control" type="date" name="screening_date" value="{{ $patient->screening_date }}" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label class="text-primary">Home Address</label>
                <textarea class="form-control" name="home_address" rows="3" cols="30">{{ $patient->home_address }}</textarea>
            </td>
        </tr>
        <tr>
            <td>
                <label class="text-primary">Mother's name</label>
                <input class="form-control" type="text" name="mother_name" value="{{ $patient->mother_name }}" />
            </td>
            <td>
                <label class="text-primary">Age</label>
                <input class="form-control" type="text" name="mother_age" value="{{ $patient->mother_age }}" />
            </td>
            <td>
                <label class="text-primary">Occupation</label>
                <input class="form-control" type="text" name="mother_occupation" value="{{ $patient->mother_occupation }}" />
            </td>
            <td>
                <label class="text-primary">Contact No.</label>
                <input class="form-control" type="text" name="mother_cp" value="{{ $patient->mother_cp }}" />
            </td>
            <td>
                <label class="text-primary">TT Status</label>
                <input class="form-control" type="text" name="mother_tt_status" value="{{ $patient->mother_tt_status }}" />
            </td>
        </tr>
        <tr>
            <td>
                <label class="text-primary">Father's Name</label>
                <input class="form-control" type="text" name="father_name" value="{{ $patient->father_name }}" />
            </td>
            <td>
                <label class="text-primary">Age</label>
                <input class="form-control" type="text" name="father_age" value="{{ $patient->father_age }}" />
            </td>
            <td>
                <label class="text-primary">Occupation</label>
                <input class="form-control" type="text" name="father_occupation" value="{{ $patient->father_occupation }}" />
            </td>
            <td>
                <label class="text-primary">Contact No.</label>
                <input class="form-control" type="text" name="father_cp" value="{{ $patient->father_cp }}" />
            </td>
        </tr>
    </table>
    <input type="submit" class="btn btn-primary m-2 " name="save" value="Save">
</form>

Here is my route;

Route::post('/patient/update', '[email protected]')->name('patient/update');

And here is my controller;

public function update(Request $request)
{
    var_dump($request);
}

Can anybody explain me why this error is happening?

Thanks, if possible can you show me the solution!

How to&Answers:

The issue is in the very first line of your Blade file, where you misspelled “method”:

<form class="" action="{{ route('patient/update') }}" metdod="post">
                                                      ^^^^^^

Without a valid method attribute in the form tag, the request will default to a GET.

Answer:

Looks like you misspelled the word method, you have metdod="post" which should be method="post".