【发布时间】: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