This is my html form;
<form action="{{url('admin/users/update/'.$user->id)}}" method="post">
{{csrf_field()}}
{{method_field('put')}}
and this is my router;
Route::post('users/update/{id}', 'UsersController@update');
and this is my controller
public function update($id)
{
//$id=$_POST['id'];
$user = \App\User::find($id);
$user->email = $_POST['email'];
$user->name = $_POST['name'];
if ($_POST['password'] != '') {
$user->password = Hash::make($_POST['password']);
}
$user->user_level = $_POST['user_level'];
$user->location =$_POST['location'];
$user->gender = $_POST['gender'];
$user->save();
My code doesn't work. How can I fix it? The error is Symphony\Component\HttpKernel\Exception\MethodNotAllowedHttpException No Message
You need to remove {{method_field ('put')}}. Because this code means that your form is being sent via put method and there is no put in the router.
Solution 1. Delete {{method_field ('put')}}.
Solution 2. Change the router definition to:
Route::put('users/update/{id}', 'UsersController@update');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With