此路由不支持 GET 方法。支持的方法:PUT。在 laravel
The GET method is not supported for this route. Supported methods: PUT. on laravel
我尝试创建一个函数来更新密码。
在我的控制器中:
public function updatePassword($id)
{
$user = User::find($id);
dd($user);
}
我的按钮打开我的页面以更新密码
<div class="float-end">
<form method="POST" action="myRoute.updatePassword">
@csrf
@method('PUT')
<button type="submit" class="btn btn-primary">
Modifier le mot de passe
</button>
</form>
</div>
我的路线:
Route::put('admin/update_password/{id}','MyController@updatePassword')->name('myRoute.updatePassword');
当我点击按钮时,出现了这个错误:
The GET method is not supported for this route. Supported methods: PUT.
感谢您的帮助!
<form method="POST" action="myRoute.updatePassword">
应该是
<form method="POST" action="{{ route('myRoute.updatePassword') }}">
更多信息:https://laravel.com/docs/8.x/urls#urls-for-named-routes
您的表单操作:
<form method="POST" action="myRoute.updatePassword">
应该是:
<form method="POST" action="{{ route('myRoute.updatePassword', $userId) }}">
您应该将 Id 作为参数传递,因为这在您的路由和 updatePassword 方法中是预期的。
您可以在文档中查看有关 Laravel 路由的更多信息:https://laravel.com/docs/8.x/routing
我尝试创建一个函数来更新密码。
在我的控制器中:
public function updatePassword($id)
{
$user = User::find($id);
dd($user);
}
我的按钮打开我的页面以更新密码
<div class="float-end">
<form method="POST" action="myRoute.updatePassword">
@csrf
@method('PUT')
<button type="submit" class="btn btn-primary">
Modifier le mot de passe
</button>
</form>
</div>
我的路线:
Route::put('admin/update_password/{id}','MyController@updatePassword')->name('myRoute.updatePassword');
当我点击按钮时,出现了这个错误:
The GET method is not supported for this route. Supported methods: PUT.
感谢您的帮助!
<form method="POST" action="myRoute.updatePassword">
应该是
<form method="POST" action="{{ route('myRoute.updatePassword') }}">
更多信息:https://laravel.com/docs/8.x/urls#urls-for-named-routes
您的表单操作:
<form method="POST" action="myRoute.updatePassword">
应该是:
<form method="POST" action="{{ route('myRoute.updatePassword', $userId) }}">
您应该将 Id 作为参数传递,因为这在您的路由和 updatePassword 方法中是预期的。
您可以在文档中查看有关 Laravel 路由的更多信息:https://laravel.com/docs/8.x/routing