假设我有User
两种方法的模型:
用户.php
class User extends Eloquent
{
/* Validation rules */
private static $rules = array(
'user' => 'unique:users|required|alpha_num',
'email' => 'required|email'
);
/* Validate against registration form */
public static function register($data)
{
$validator = Validator::make($data, static::$rules);
if($validator->fails())
{
/*... do someting */
}
else
{
/* .. do something else */
}
}
/* Validate against update form */
public static function update($data)
{
$validator = Validator::make($data, static::$rules);
if($validator->fails())
{
/*... do someting */
}
else
{
/* .. do something else */
}
}
}
我的问题:我怎样才能使验证规则成为可选的,所以即使数据update()
只是email
字段,它也会忽略user
并仍然验证到true
.
这甚至可能还是我错过了什么?
对不起,我的英语不好。