I've installed TwigBridge for Laravel 4 and I am trying to adapt some templates I've already got from Blade to Twig.
I want display some validation errors at the top of a view.
I had the following in Blade (which worked OK):
@if (isset($errors))
@foreach ($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
@endif
I've tried to convert it to Twig but nothing gets displayed.
{% if errors %}
{% for error in errors %}
<p>{{ error }}</p>
{% endfor %}
{% endif %}
However, if I try:
{{ errors }}
I do get some output:
{"name":["The name field is required."]}
What do I need to change in order to get it to work?
Any advice appreciated.
Thanks
I worked it out after I looked at the code in Illuminate/Support/MessageBag:
{% if errors.any %}
{% for error in errors.all %}
<p>{{ error }}</p>
{% endfor %}
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With