php - Structure of $errors with Laravel 4 -
in laravel 4 whenever on every request there variable $errors show errors have happened in request. has structure this:
object(illuminate\support\messagebag)#120 (2) { ["messages":protected]=> array(1) { ["email"]=> array(1) { [0]=> string(40) "the email must valid email address." } } ["format":protected]=> string(8) ":message" } i figured put code on header of app give output user, listing relevant message, this:
@if (count($errors->messages)) <div class="error-box"> <ul> @foreach ($errors->messages $error) <li>{{{ $error }}}</li> @endforeach </ul> </div> @endif but apparently cant access messages this.
can please explain me structure of messagebar $errors, , more importantly, how loop through error messages, display them?
you cannot $errors->messages directly because illuminate\support\messagebag has messages property ["messages":protected].
what need use all() this:
@foreach ($errors->all() $error) <li>{{{ $error }}}</li> @endforeach or in fact, since messagebag can behave array, can count() , foreach on directly like:
@if (count($errors)) // or $errors->count() <div class="error-box"> <ul> @foreach ($errors $error) <li>{{{ $error }}}</li> @endforeach </ul> </div> @endif you can see full list of methods can perform laravel's messagebag at:
Comments
Post a Comment