alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

How to implement Laravel password validation rules as string in arrays in laravel ?

How to implement Laravel password validation rules as string in arrays in laravel ?

Try This 

 // for illustration
class Mock {
    public function __call($name, $args) {
        printf("called: %s(%s)\n", $name, implode(', ', $args));
        return $this;
    }
    
    // this is awful. never do this.
    // in Laravel the min() function, and only this function, is basically
    // an alias to the constructor, which is weird.
    public static function __callStatic($name, $args) {
        return (new self())->$name(...$args);
    }
}

$params = [
    'min' => [8],
    'letters' => [],
    'numbers' => [],
    'mixedCase' => [],
    'uncompromised' => [3]
];

$o = NULL;
foreach( $params as $func => $args ) {
    if( is_null($o) ) {
        $o = Mock::$func(...$args);
    } else {
        $o = $o->$func(...$args);
    }
} 

Output:

 called: min(8)
called: letters()
called: numbers()
called: mixedCase()
called: uncompromised(3)

31 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online