php - required_without_all validator repeats error message over and over -


i'm building roster system side project , on 1 of pages can change regular hours works.

on page have checkbox each day of week, can go through , select appropriate days person works.

they need work @ least 1 day , @ least 1 of checkboxes needs checked when submitted.

to test using required_without_all rule of laravel's validator.

it works perfectly, if no boxes checked redirect , spit out same error message 7 times (as there 7 checkboxes each day of week).

i using custom error messages why error message same, if didn't wouldn't want similar error message being repeated on , over.

this validator looks like:

$validator = validator::make($request->all(), [             'mondaycheckbox' => 'required_without_all:tuesdaycheckbox,wednesdaycheckbox,thursdaycheckbox,fridaycheckbox,saturdaycheckbox,sundaycheckbox',             'tuesdaycheckbox' => 'required_without_all:mondaycheckbox,wednesdaycheckbox,thursdaycheckbox,fridaycheckbox,saturdaycheckbox,sundaycheckbox',             'wednesdaycheckbox' => 'required_without_all:mondaycheckbox,tuesdaycheckbox,thursdaycheckbox,fridaycheckbox,saturdaycheckbox,sundaycheckbox',             'thursdaycheckbox' => 'required_without_all:mondaycheckbox,tuesdaycheckbox,wednesdaycheckbox,fridaycheckbox,saturdaycheckbox,sundaycheckbox',             'fridaycheckbox' => 'required_without_all:mondaycheckbox,tuesdaycheckbox,wednesdaycheckbox,thursdaycheckbox,saturdaycheckbox,sundaycheckbox',             'saturdaycheckbox' => 'required_without_all:mondaycheckbox,tuesdaycheckbox,wednesdaycheckbox,thursdaycheckbox,fridaycheckbox,sundaycheckbox',             'sundaycheckbox' => 'required_without_all:mondaycheckbox,tuesdaycheckbox,wednesdaycheckbox,thursdaycheckbox,fridaycheckbox,saturdaycheckbox',             'effective_from' => 'date',             ], [             'mondaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'tuesdaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'wednesdaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'thursdaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'fridaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'saturdaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'sundaycheckbox.required_without_all' => 'surely working @ least 1 day!',             'effective_from.date' => 'you have provided invalid date when hours effective from!',             ]);          if ($validator->fails())         {             return redirect::back()                 ->witherrors($validator)                 ->withinput();         } 

so if no boxes checked on submission, error surely working @ least 1 day! shown 7 times.

i displaying errors on page this:

@if (count($errors) > 0)     <div class="alert alert-danger">         <p><b>there problems:</b></p>         <ul>             @foreach ($errors->all() $error)                 <li>{{ $error }}</li>             @endforeach         </ul>     </div> @endif 

is there anyway show once?

there many ways go around this. since js hacks on table too, can come in blade end , (feel free use own favourite array manipulation functions):

<ul>      <li>         {{-- show error message once --}}         @if( $errors->has('mondaycheckbox') || $errors->has('tuesdaycheckbox') ||  $errors->has('wednesdaycheckbox') ||  $errors->has('thursdaycheckbox') ||  $errors->has('fridaycheckbox') ||  $errors->has('saturdaycheckbox') ||  $errors->has('sundaycheckbox') )             surely working @ least 1 day!         @endif     </li>      @foreach ($errors->all() $error)          {{-- show other errors not related checkboxes --}}         @unless($error == 'surely working @ least 1 day!')             <li>                 {{ $error }}             </li>         @endunless      @endforeach </ul> 

the other way deal illuminate\contracts\support\messagebag in validator after validation hook , clean things there.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -