'方法 [validateString] 不存在。在 Laravel 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24732868/
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-14 09:48:28  来源:igfitidea点击:

'Method [validateString] does not exist.' in laravel Validation

phpvalidationlaravel

提问by Jakub Kohout

I want to validate my form input but it throws me this error in my Laravel.logfile

我想验证我的表单输入,但它在我的Laravel.log文件中抛出了这个错误

production.ERROR: exception 'BadMethodCallException' with message 'Method [validateString] does not exist.' in C:\xampp\htdocs\testing\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:2405

production.ERROR: 异常“BadMethodCallException”,消息“方法 [validateString] 不存在”。在 C:\xampp\htdocs\testing\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:2405

This is my Dog model

这是我的狗模型

class Dog extends Eloquent {

// Add your validation rules here
public static $rules = [
    'name' => 'required|string',
    'age' => 'required|integer'
];

public static $customMessages = array(
    'required' => 'Man the Name atribute is REQUIRED. Fill it man.'
);

// Don't forget to fill this array
protected $fillable = ['name', 'age'];


public static function validate($data) {
    return Validator::make($data, static::$rules);
}

}

}

And in my DogsController here I validate my data

在我的 DogsController 中,我验证了我的数据

public function update($id)
{

    $dog = $this->DogRepo->find($id);

    if($dog)
    {   
        // $dog = $this->dogRepo->update(array_merge(['id' => $id], Input::all()));

        $validation = Dog::validate(Input::all());

        if ($validation->fails()) {
            return 'wrong data';
        } else {
            return 'ok data';
        }


        if($dog->save())
        {
            return Redirect::route('dogs.show', $id)->with('message', 'The dog has been updated!');
        }

        return Redirect::route('dogs.edit', $id)->withInput()->withErrors($this->dogRepo->errors());
    }

    App::abort(404);

}

Any Ideas what I'm doing wrong?

任何想法我做错了什么?

Thank you very much for any help.

非常感谢您的帮助。

采纳答案by lagbox

In Laravel < 4.2

在 Laravel < 4.2

There is no validation rule named string.

没有名为 的验证规则string

Laravel 4.1 - Validation - Available Rules

Laravel 4.1 - 验证 - 可用规则

In Laravel >= 4.2 there is a string rule

在 Laravel >= 4.2 中有一个字符串规则

Updated to reflect newer versions of Laravel.

更新以反映 Laravel 的更新版本。