简体   繁体   English

如何在刀片laravel中添加简写if语句?

[英]How can I add a shorthand if statement in blade, laravel?

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? 如何在刀片laravel中添加if语句的速记if语句,该语句在我的引导程序表单输入中添加了一个类'alert-danger',在进行表单验证时为它提供了红色边框/轮廓? 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. 请记住,我是Laravel和Blade的新手。 Thank you for your help! 谢谢您的帮助!

您可以尝试这样的事情

{!! Form::email('email', null, ['class'=> $errors->first('email') ? 'alert-danger form-control' : 'form-control']) !!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在视图Laravel刀片上的类中添加运算符三元? - How can I add operator ternary in class on the view laravel blade? 我如何在 Laravel Blade 上实现这段代码? - how can i implement this code on laravel blade? 如何在 laravel 的 foreach 刀片中添加两个数字并显示总数 - How can i add two numbers in foreach blade in laravel and display the total 如何自动向 Laravel Blade 模板中的所有链接添加一些查询参数? - How can I automatically add some query parameters to all links in Laravel Blade templates? 如何在此嵌套foreach的末尾添加空行? - Laravel Blade - How can I add a blank row at the end of this nested foreach? - Laravel Blade 如何在laravel刀片上添加HTML 5类型属性? - How do I add HTML 5 type attribute to laravel blade? 如何在Laravel中添加一个类,以便在Blade中可用? - How do I add a class in Laravel so it is available in Blade? Laravel Blade 如何使用 if 语句为空或空 - Laravel Blade how to use if statement for null or empty 如何在 laravel 刀片页面中使用多个 if 语句 - How to use multiple if statement in laravel blade page 如何解决将刀片语法转换为php的问题? 如果刀片中的语句到PHP - How can I fix the problem in converting blade syntax to php? if statement in blade to php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM