gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:45:20 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com