php - How do I add my message to the $errors variable in Laravel 4.2 -


i tried extending laravel 4.2 validation check if all form data valid (not fields) according business rules.

i not extend custom validator in normal way (either hacky or not dry enough) decided add business rules check after validator succeeds, , add own error messages , redirect.

it still ugly , not work happy if tells me how add message session. if feel telling me how should use laravel's custom validators i've included more code can more specific..:

$validator = validator::make(input::all(), $this->validationrules, $this->validationmessages); if ($validator->fails()) {     if (0 == $id) {         return redirect::route('x.create')->witherrors($validator)->withinput();     } else {         return redirect::route('x.edit', $id)->witherrors($validator)->withinput();     } } else {     //tests     if ($this->alreadyexists($id)) {         $messages = new messagebag();         if ($request->getsession()->get('errors')){             $messages = $request->getsession()->get('errors')->getbag('default');         }         $messages->add('form', 'same data exists');          if (0 == $id) {             return redirect::route('x.create')->witherrors($messages)->withinput();         } else {             return redirect::route('x.edit', $id)->witherrors($messages)->withinput();         }     } }  //all ok. save/update entity ... 

the code setting session first 5 lines after check alreadyexists. got forum doesn't seem work ok (i "non-object" exceptions if include code seems corrupts session object)

i don't think have time upgrade l5.

i solved creating new error message bag , adding redirect:

$mb = new illuminate\support\messagebag(); $mb->add("form", "same data exists"); ... return redirect::route('x.create')->witherrors($mb)->withinput(); 

seems needed add full namespace bag, of needed rest :)

the validation logic still bad no time tinker now.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -