php - Laravel 4.2 validation: required_unless -


recently have been learning laravel , came accross validator problem solved using validator rule required_unless laravel 5.2:

$validator = validator::make(     array(         'social_id' => $social_id,         'login_by' => $login_by     ), array(         'social_id' => 'required_unless:login_by,manual',         'login_by' => "in:manual,google,facebook, stack_exchange, myspace"     ) ); 

problem use laravel 4.2 , validation rule not implemented jet.

is there other validating rule use or other way?

if not, how write custom validation rule , put it?

edit: do:

$validator = validator::make(     array(         'social_id' => $social_id,         'login_by' => $login_by     ), array(         'social_id' => 'required_if:login_by,google,facebook, stack_exchange, myspace',         'login_by' => "in:manual,google,facebook, stack_exchange, myspace"     ) ); 

...but workaround not elegant permanent solution.

you can extend validator extend method.

something this

validator::extend('required_unless', function ($attribute, $value, $parameters) {     // implement version of required_unless here }); 

and steal bit of logic l5.2 here

you can see doc on extend here


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -