Home > database >  The GET method is not supported for this route. Supported methods: PUT. on laravel
The GET method is not supported for this route. Supported methods: PUT. on laravel

Time:01-12

I try to create a function to uptade a password.

in my controller:

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

    dd($user);
}

my button to open my page for update password

<div >
    <form method="POST" action="myRoute.updatePassword">
        @csrf
        @method('PUT')
                    
        <button type="submit" >
            Modifier le mot de passe
        </button>
    </form>
</div>

and my route :

Route::put('admin/update_password/{id}','MyController@updatePassword')->name('myRoute.updatePassword');

And when i click on the button, i have this error :

The GET method is not supported for this route. Supported methods: PUT.

Thanks for you'r help !

CodePudding user response:

<form method="POST" action="myRoute.updatePassword">

Should be

<form method="POST" action="{{ route('myRoute.updatePassword') }}">

More information: https://laravel.com/docs/8.x/urls#urls-for-named-routes

CodePudding user response:

Your form action:

<form method="POST" action="myRoute.updatePassword">

Should be:

<form method="POST" action="{{ route('myRoute.updatePassword', $userId) }}">

You should pass the Id as a parameter since this is expected in your route and in your updatePassword method.

You can check more info about Laravel Routing in the docs: https://laravel.com/docs/8.x/routing

  •  Tags:  
  • Related