简体   繁体   English

获取Symfony \\组件\\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException

[英]Getting Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

I'm sending a PUT request that handles input data and updates a record, but I get the above response. 我正在发送一个处理输入数据并更新记录的PUT请求,但是得到了以上响应。 The problem doesn't seem to be the route, however, because if I do dd($user) after the $user = User::whereId($id)->firstOrFail(); 但是,问题似乎不是路由,因为如果在$user = User::whereId($id)->firstOrFail();之后执行dd($user) $user = User::whereId($id)->firstOrFail(); line, I get the object returned correctly. 行,我得到正确返回的对象。

Yet, when it comes time to validate it, it throws this error. 但是,当需要进行验证时,会引发此错误。

# routes
Route::resource('users', 'UsersController', ['only' => ['index', 'show', 'update']]);

# api call
PUT /users/2

# controller
public function update($id)
{

    $user = User::whereId($id)->firstOrFail();

    $input = Input::all();

    $this->userForm->validate($input);

    $user->fill($input)->save();

    return $user->toJson();

}

# userForm class

<?php namespace Olp\Forms;

use Laracasts\Validation\FormValidator;

class UserForm extends FormValidator {

    protected $rules = [
        'email'         => 'required|email|unique:users',
        'password'      => 'required',
        'password_confirmation' => 'required|same:password',
        'firstname'     => 'required',
        'lastname'      => 'required',
        'schoolname'    => 'required',
        'address1'      => 'required',
        'address2'      => 'required',
        'postcode'      => 'required',
        'city'          => 'required'
    ];
}

and in my UserController: 在我的UserController中:

use Olp\Forms\UserForm;

class UsersController extends \BaseController {

    function __construct(UserForm $userForm)
    {
        $this->userForm = $userForm;
    }

I'm not a Laravel guy, but a quick check on their documentation indicates that Resource Controllers support PUT in addition to other HTTP verbs. 我不是Laravel专家,但是快速浏览一下他们的文档表明, 资源控制器除了支持其他HTTP动词外,还支持PUT。

I was not able to figure out how to add HTTP verb support to an arbitrary action, but this indicates that you can name a controller action prefixed with the verb it responds to 我无法弄清楚如何HTTP动词支持添加到任意的动作,但是表明你能说出与动词前缀的控制器操作它响应

public function putUpdate($id)

暂无
暂无

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

相关问题 Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException,删除按钮 - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException, delete button 获取Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Getting Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel中的Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException错误 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Error in Laravel Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException:找不到对象 - Symfony\Component\HttpKernel\Exception\NotFoundHttpException: object not found Laravel 5.4中的Symfony \\ Component \\ HttpKernel \\ Exception \\ HttpException错误 - Symfony\Component\HttpKernel\Exception\HttpException Error in Laravel 5.4 Laravel 5 Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: POST http://localhost/myproject/public/leads - Laravel 5 Symfony\Component\HttpKernel\Exception\NotFoundHttpException: POST http://localhost/myproject/public/leads request.ERROR: Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: 没有找到“GET /”的路由 - request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for “GET /” 找不到类&#39;Symfony \\ Component \\ HttpKernel \\ DependencyInjection \\ ConfigurableExtension&#39; - Class 'Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension' not found 找不到接口&#39;Symfony \\ Component \\ HttpKernel \\ HttpKernelInterface&#39; - Interface 'Symfony\Component\HttpKernel\HttpKernelInterface' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM