Laravel如何制作on_or_after验证规则?

时间:2015-06-22 15:58:24

标签: php laravel laravel-4

我一直关注docs和一些stackoverflow帖子,但似乎我犯了一个我无法弄清楚的错误。我收到错误ClassLoader::addDirectories(array( app_path().'/commands', app_path().'/controllers', app_path().'/models', app_path().'/database/seeds', app_path().'/custom', )); 不存在。

应用/启动/ global.php

    <?php

    class CustomValidator extends Illuminate\Validation\Validator
    {

      public function validateOnOrAfter($attribute, $value, $parameters)
      {
        $OnOrAfter = strtotime($this->getValue($parameters[0]));
        $ToValidateDate = strtotime($value);

        return ($OnOrAfter >= $ToValidateDate);
      }

    }

    Validator::resolver(function($translator, $data, $rules, $messages)
      {
        $messages = array(
          'on_or_after' => 'The :attribute must be on of after :value'
        );

        return new CustomValidator(($translator, $data, $rules, $messages);
      }

应用/定制/ validation.php

Validator::extend

修改
无奈之下,我还尝试在controller@store方法中直接使用docs Validator::extend( 'on_or_after', function($attribute, $value, $parameters) { $OnOrAfterThisDate = Input::get($parameters[0]); $ToValidateDate = ($value); //dd(strtotime($OnOrAfterThisDate) <= strtotime($ToValidateDate)); return (strtotime($OnOrAfterThisDate) <= strtotime($ToValidateDate)); }); Validator::replacer('on_or_after', function($message, $attribute, $rules, $parameters) { $messages = array( 'on_or_after' => 'The :attribute must be on of after :parameter' ); }); 中的其他方法(必须对代码进行一些更改)并且执行查找尽管返回值为false,但是在我的验证中它没有做任何事情。

应用/控制器/ ProgramSession @存储

struct point {
   float *x;
   float *y;
   float *z;
};

0 个答案:

没有答案