Laravel before today rule... how to do

try this:

'birthday' => 'date_format:Y-m-d|before:today',

bye


You can't use a function when defining class member variables. You'll have to move that part to your constructor:

<?php
class Foo {
    public static $rules = array(
        'first_name' => 'required|alpha-dash',
        'last_name' => ' required|alpha-dash',
        'media_release' => 'required|boolean'
    );
    public function __construct()
    {
        self::$rules['birthday'] = 'before:' . date('Y-m-d');
    }

EDIT:

The above solution may not work in Laravel. You may have to use a "Custom Validator" instead:

http://laravel.com/docs/4.2/validation#custom-validation-rules

UPDATE:

Looks like Laravel 5 introduced a better solution. See the answer by Fernando, below.


Just for future users:

Laravel 5 using form requests:

'birthday' => 'before:today',    // Doesn't accept today date
'birthday' => 'before:tomorrow', // Accept today date

Tags:

Php

Laravel