One-shot laravel validator -


i have form searches something. based on form, validate if input correct:

$validator = validator::make(input::all() , array(     'address'  =>'required',  ));  if($validator->fails()) {     return redirect::to('/')->witherrors($validator); } 

after this, want validate else (that result object isn't empty), unrelated search. in other words, it's not input form.

1) create validator validate this? or 2) there better way check value , spawn object can returned "witherrors"?

update

this isn't working me:

$validator = validator::make(     array(          'searches' => sizeof($search)      ) ,      array(         'searches'  => 'required|min:1'     ) );  if($validator->fails()) {     return redirect::to('/')->witherrors($validator); } 

it's not working because reason it's picking "searches" item should validated "sometimes"

you have 2 ways. 1 custom validator

or there simpler way,

suppose,

private function foo()     {         $data = ''; //retrieved data error here whatever call want make          return !empty($data) ? true : false;     } 

in controller,

public function bar() {     if(!$this->foo())     {             $messages = new \illuminate\support\messagebag;                             // should use interface here. directly  made object call sake of simplicity.             $messages->add('custom', 'custom error');             return redirect::back()->witherrors($messages)->withinput();     } } 

in view:

@if($errors->has('custom'))     <p>custom error output.</p> @endif 

it outline give idea.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -