0

So my question is how to mark/show messages via javascript after server-side validation. I know there's the $errors inside blade views but there's no way of telling which element could not be validated. The only way of knowing is to do $errors->first(...) but then you get stuck with only this frustrating option:

<div class="form-group {{ $errors->has('password') ? 'has-error' : '' }}">
    <input type="password" class="form-control" {{ $errors->has('password') ? 'title=' . $errors->first('password') : '' }} placeholder="Password" name="password" required="required">
</div>

While it's acceptable to do that, I'm aiming at reusability, something that can be easily implemented and troubleshot later on other pages.

Any idea would be appreciated.

Matheus Simon
  • 668
  • 11
  • 34

1 Answers1

2

Have you tried the Laravel Collective form package?

This allows you to quickly build forms that not only bind to model values, but easily re-populate if there is a validation error on the server!

It make easier to create forms, retrieve old values and display errors. It also make the code cleaner. For example:

{!! Form::open(['url' => 'foo/bar']) !!}

    {{ Form::password('password', ['class' => 'awesome']) }}

{!! Form::close() !!}

Check the docs.

Rafael Berro
  • 2,518
  • 1
  • 17
  • 24