2014-07-14 54 views
2

我想驗證我的形式輸入,但它拋出我這個錯誤在我Laravel.log文件'方法[validateString]不存在。'在laravel驗證

production.ERROR:「方法[validateString]不存在」例外「BadMethodCallException」有消息在C:\ XAMPP \ htdocs中\測試\供應商\ laravel \框架的\ src \照亮\確認\ 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); 
} 

}

而且在我的狗控制器在這裏我驗證我的數據

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

} 

任何想法我做錯了什麼?

非常感謝您的幫助。

回答

1

在Laravel < 4.2

有一個名爲string沒有驗證規則。

Laravel 4.1 - Validation - Available Rules

在Laravel> = 4.2有一個字符串規則

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

+0

有你的鏈接... – Tom

+0

@Tom thx,更新到包括比4.1更新的版本。 – lagbox