laravel 方法 Illuminate\Validation\Validator::validateRequest 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50001466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:53:22  来源:igfitidea点击:

laravel Method Illuminate\Validation\Validator::validateRequest does not exist

formslaravelvalidation

提问by Daniel Masih

when i submit a form and run form validation then it gaves me this error but my form validation is working on other page In that file \vendor\laravel\framework\src\Illuminate\Validation\Validator.php

当我提交表单并运行表单验证时,它给了我这个错误,但我的表单验证正在其他页面上工作在该文件\vendor\laravel\framework\src\Illuminate\Validation\Validator.php

/**
 * Handle dynamic calls to class methods.
 *
 * @param  string  $method
 * @param  array   $parameters
 * @return mixed
 *
 * @throws \BadMethodCallException
 */
public function __call($method, $parameters)
{
    $rule = Str::snake(substr($method, 8));

    if (isset($this->extensions[$rule])) {
        return $this->callExtension($rule, $parameters);
    }

    throw new BadMethodCallException(sprintf(
        'Method %s::%s does not exist.', static::class, $method
    ));
}

Errror=Method Illuminate\Validation\Validator::validateRequest does not exist

错误 =方法 Illuminate\Validation\Validator::validateRequest 不存在

回答by Marta

Maybe you wrote requestinstead of required? Like here:

也许你写的是request而不是required?像这儿:

$data = $request->validate([
    'field' => 'request|string|max:255',
]);

Trying to fire validateRequestmethod suggest you were trying to use 'request' validation rule which doesn't exist.

尝试触发validateRequest方法表明您正在尝试使用不存在的“请求”验证规则。

All valid rules you can find here, but I think you just made a typo.

您可以在此处找到所有有效规则,但我认为您只是打错了字。

回答by aj3sh

You should use a Validator facade class

您应该使用 Validator 外观类

In you Controller

在你的控制器

use Validator;

See link Laravel validation

请参阅链接Laravel 验证

回答by Nur Alam

You can validate the form as below:

您可以验证表单如下:

public function formSubmit(Request $request){
    $request->validate([
        'name' => 'required',
        'address' => 'required',
        'phone' => 'required',
    ]);

    $customer =Customer::insert([
        'name' => $request->name,
        'address' => $request->address,
        'phone' => $request->phone
    ]);
    dd($customer);
    echo "Data send Successfully";
}