简体   繁体   English

更新中的Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException

[英]Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException in update

When I click on update button I get next error: 当我单击更新按钮时,出现下一个错误:

Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException No message Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException没有消息

For update I have next routes: 要更新,我有下一条路线:

Route::post('edit/user/{id}','UsersController@update');
Route::get('edit/user/{id}','UsersController@edit');

As you see, I use post method for update. 如您所见,我使用post方法进行更新。

My controller code: 我的控制器代码:

public function edit($id){
            $user = User::where('id',$id)
            ->first();
            return view('user.edit', compact('user','id'));
        }

        public function update(Request $request, $id){
            $user = new User();
            $data_user = $this->validate($request,$rules_user);
            $data_user['id'] = $id;
            $user->updateUser($data_user);
            return redirect('/users');
        }

My update.blade.php code: 我的update.blade.php代码:

   @extends('layouts.app')

@section('content')
<div class="container">
@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div><br />
@endif
    <div class="row">
    <form method="post" action="{{action('UsersController@update', $id)}}" >
        {{csrf_field()}}
        <input name="_method" type="hidden" value="PATCH">
        <div class="form-group">
       <input type="hidden" value="{{csrf_token()}}" name="_token" /> 
            <label for="name">User name:</label>
            <input type="text" class="form-control" name="name" value={{$user->name}} />
        </div>
        <button type="submit" class="btn btn-primary">Update</button>
        </form>
    </div>
</div>
@endsection

In your action attribute you specified a direct call to the controller without going to the route URI. 在action属性中,您指定了对控制器的直接调用,而无需访问路由URI。 Therefore address the action attribute to this 因此,将动作属性处理为此

<form method="post" action="edit/user/{{$id}}" >

It will go through the route and validates the CSRF then proceeds to the request 它将通过路线并验证CSRF,然后继续进行请求

您的路线应为“张贴”而不是“张贴”

Route::put('edit/user/{id}','UsersController@update’)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新错误-Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException没有消息 - update error - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message Laravel-更新内容错误Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException - Laravel - Update Content Error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException-Laravel 5.7 - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException - Laravel 5.7 Laravel 5.6上的Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException on laravel 5.6 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException laravel 8 错误 - Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException laravel 8 error Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException,删除按钮 - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException, delete button Laravel:Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException没有消息 - Laravel : Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message Laravel:POST - &gt; Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException - Laravel: POST -> Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException没有消息抛出新的MethodNotAllowedHttpException($ others); - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message throw new MethodNotAllowedHttpException($others); 异常&#39;Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException&#39;上传大文件laravel - exception 'Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException' Uploading large files laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM