【问题标题】:'Method [validateString] does not exist.' in laravel Validation'方法 [validateString] 不存在。'在 laravel 验证中
【发布时间】:2014-09-04 03:40:35
【问题描述】:

我想验证我的表单输入,但它在我的 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);

}

任何想法我做错了什么?

非常感谢您的帮助。

【问题讨论】:

    标签: php validation laravel


    【解决方案1】:

    在 Laravel

    没有名为string的验证规则。

    Laravel 4.1 - Validation - Available Rules

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-22
      • 2018-01-29
      • 2018-10-12
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 1970-01-01
      • 2016-06-26
      相关资源
      最近更新 更多