我正在使用Laravel 4.2和mysql db.
我有一个考试表,我正在参加考试,字段是 - >id | examdate | batch | chapter | totalmarks
我$table->unique( array('examdate','batch','chapter') );在模式构建器中使用组合的唯一键.
现在我想为它添加一个验证规则.我知道我可以通过laravel唯一验证器规则添加唯一验证,但问题是,它只检查一个字段.
我希望它为3个字段组合添加唯一性(用户必须无法添加具有相同值组合的examdate,batch和chapter字段的第二行).
是否有可能在laravel 4中进行.如果不可能,有任何解决方法吗?
要向Laravel添加新验证,我已经这样做了:
做了一个所谓的新文件customValidation.php中app/start/
然后把它包括进来app/start/global.php并用echo()它测试它并且它起作用了.所以它现在被加载到应用程序中.
然后我编写了以下代码来验证Laravel中的复选框:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class customValidate extends Illuminate\Validation\Validator
{
public function validateCheckbox($attribute, $value, $parameters)
{
//if(isset($value)) { return true; } else { return true; }
echo "this is the: " . $value;
}
}
/**
* Resolvers for Custom Validations
*/ …Run Code Online (Sandbox Code Playgroud)