Laravel until today rules ... how to do it
For this rule, I am getting the error syntax error, unexpected '.', expecting ')'
public static $rules = array(
'first_name' => 'required|alpha-dash',
'last_name' => ' required|alpha-dash',
'media_release' => 'required|boolean',
'birthday' => 'before:' . date('Y-m-d')
);
I can't figure out why this won't work. I am running Laravel 4.2.12
+3
source to share
4 answers
You cannot use a function when defining member variables of a class. You will have to move this 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 need to use the "Custom Validator":
http://laravel.com/docs/4.2/validation#custom-validation-rules
+1
source to share