How can I solve “Type error: Argument 1 passed to App\\Http\\Controllers\\Controller::validate() must be an instance of Illuminate\\Http\\Request,”?

匆匆过客 提交于 2019-12-02 11:27:40

The first parameter passed to validate should be an instance of Illuminate\Http\Request.

So you need to pass the $request object to validate method as the first parameter like this

$this->validate($request, [
    'validation' => 'rules',
]);

If you are receiving input as JSON make sure Content-Type header of the request is set to application/json

jQuery ajax example

$.ajax({
    url: url,
    type: 'POST',
    data: {
        'id': 'value', 
        'quantity': 'value'
    },
    dataType: 'json',
    contentType: 'application/json'
});

If you are using use Request; in your controller, then replace it with,

use Illuminate\Http\Request;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!