Reputation: 522
How can I add a shorthand if statement in blade, laravel, that adds a class to my bootstrap form input of 'alert-danger', that gives it a red border/outline when doing form validation? Basically I want to check if there is a form error and if there is I want the input to have a red outline.
This is what I have but the class of 'alert-danger' is not being applied:
<div class="form-group">
{!! Form::label('email', 'Email:') !!}
{!! Form::email('email', null, ['class'=>'form-control'], $errors->first('email') ? ['class'=>'alert-danger'] : '') !!}
</div>
Please keep in mind I'm fairly new to Laravel and Blade. Thank you for your help!
Upvotes: 2
Views: 1170
Reputation: 619
You can try something like this
{!! Form::email('email', null, ['class'=> $errors->first('email') ? 'alert-danger form-control' : 'form-control']) !!}
Upvotes: 2