Support the ongoing development of Laravel.io →
Eloquent Validation
Last updated 2 years ago.
0
Solution

What if you put that in static function of boot method in your model?

class UrModel extends \Eloquent {
    public static $rules = array(
        'name' => 'required|unique:players|alpha|between:2,30',
        //'city' => 'integer|in:' . implode(',', array_keys(\Config::get('app.cities'))),
    );
    public static function boot() {
        parent::boot();
        $config = array(1,2,3,4);
        self::$rules['city'] = 'integer|in:'.implode(',', $config);
    }
}
Last updated 2 years ago.
0

yfktn said:

What if you put that in static function of boot method in your model?

Hmm I totally forgot about the boot. It did the trick for me :)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ranisalt ranisalt Joined 10 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.