laravel-ardent / ardent

Self-validating, secure and smart models for Laravel's Eloquent ORM
BSD 3-Clause "New" or "Revised" License
1.39k stars 211 forks source link

initialization of the static variable Ardent::$rules #292

Open Cyrille37 opened 8 years ago

Cyrille37 commented 8 years ago

Hi, not a bug but a needed feature.

I would like to define some Ardent::$rules with concatenation of constants. But Php5.6 does not want concatenation in declaration of static variables.

class Abc extends Ardent
{
    const NAME_LENGTH_MAX = 40 ;

    public static $rules = array (
        // Here, wants to replace 40 by Abc::NAME_LENGTH_MAX
        'name' => ['required','between:3,40', 'regex:/^[[:word:] \-]+$/u'],
        // Syntax error :
        'name' => ['required','between:3,'.Abc::NAME_LENGTH_MAX, 'regex:/^[[:word:] \-]+$/u'],
    );

Is there another way,place where we can initialize Ardent::$rules values ?

Cheers

igorsantos07 commented 8 years ago

This could be bad memory block in my brain as I'm not accessing the source now, but have you tried adding a rules() method?

If that does not work, that's probably how it would be implemented hmmm, with the method returning the static var by default and replacing all variable calls. On 6 Feb 2016 09:05, "Cyrille Giquello" notifications@github.com wrote:

Hi, not a bug but a needed feature

I would like to define some Ardent::$rules with concatenation of constants But Php56 does not want concatenation in declaration of static variables

class Abc extends Ardent{ const NAME_LENGTH_MAX = 40 ; public static $rules = array ( // Here, wants to replace 40 by Abc::NAME_LENGTH_MAX 'name' => ['required','between:3,40', 'regex:/^[[:word:] -]+$/u'], // Syntax error : 'name' => ['required','between:3,'Abc::NAME_LENGTH_MAX, 'regex:/^[[:word:] -]+$/u'], );

Is there another way,place where we can initialize Ardent::$rules values ?

Cheers

— Reply to this email directly or view it on GitHub https://github.com/laravel-ardent/ardent/issues/292.