0
我創建了一個帶有「驗證」功能的庫,用於驗證我的字段,在該功能中,規則是從配置位置自動檢索的。爲了保持乾淨,我不用這個'驗證'函數來返回驗證器對象,而是我喜歡這樣做,並想知道這是否可以做?你會怎麼做呢?創建靜態變量來保存Laravel中的驗證器
// myController的
if(!My_val::validate($input))
return $this->response(My_val::$val->messages()->first());
//我的圖書館
class My_val {
public static $val;
public function __construct() {
$val= null;
}
public static function validate($data) {
// commented out section ---- here the rules are extracted from a config file
self::$val= Validator::make($data);
return self::$val->passes();
}
}
很好的資源謝謝! – user391986