php - “方法 [validateString] 不存在。”在 laravel 验证

标签 php validation laravel

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

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

这是我的狗模型

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);
}

然后在我的 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);

}

知道我做错了什么吗?

非常感谢您的帮助。

最佳答案

在 Laravel < 4.2

没有名为string 的验证规则。

Laravel 4.1 - Validation - Available Rules

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

已更新以反射(reflect)更新版本的 Laravel。

关于php - “方法 [validateString] 不存在。”在 laravel 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24732868/

相关文章:

reactjs - Redux 表单复选框验证

filter - 表单输入过滤和验证中的黑名单与白名单

php - Laravel 文件上传添加到集合移动文件在数字文件夹中

php - Laravel 5 中的 "Call to a member function put() on null"

PHP header 位置重定向不起作用 - 为什么?

javascript - $index 不存在于 ng-repeat 中 - 答案在我原来的帖子中

java - Spring 和 Hibernate 的 Bean 验证不起作用

php - 按类别 id laravel 检索帖子

php - 无法使用 PHP ssh2_exec() 以 super 用户权限执行命令

php - 错误 : file is encrypted or is not a database