在 laravel 中有 if 条件
Having if condition in laravel
这是我在 php 中的条件,我正在尝试将其转换为 laravel
<?php
if ($DriverDetail['IsActive']=='1')
{
?>
<span class='account-active'></span>
<?php
}
else
{
?>
<span class='account-blocked'></span>
<?php
}
?>
我试过
{{ $DriverDetail['IsActive'] }}
并在 {{}}
中连接 <span class='account-blocked'></span>
但这是获得 laravel 条件的最佳方式,它相当于我的 php 代码
尝试:
<span class='{{ $DriverDetail['IsActive'] ? 'account-active' : 'account-blocked' }}'></span>
或者,如果您想要分隔整个跨度:
{{ $DriverDetail['IsActive'] ? "<span class='account-active'></span>" : "<span class='account-blocked'></span>" }}
这是使用三元运算符(文档 here). Basically, any value that evaluates to a boolean true will output the first expression (after the '?'), otherwise it outputs the second expression (after the ':'). In this case, the string '1', or even the number 1, evaluates to a boolean true, so the ternary operator will evaluate to the "true" expression ('account-active'). Implicit boolean conversions are covered in the docs here。
试试这个...
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif
使用 blade 模板系统,一个明确的方法是:
@if ($DriverDetail['IsActive'])
<span class='account-active'></span>
@else
<span class='account-blocked'></span>
@endif
这是我在 php 中的条件,我正在尝试将其转换为 laravel
<?php
if ($DriverDetail['IsActive']=='1')
{
?>
<span class='account-active'></span>
<?php
}
else
{
?>
<span class='account-blocked'></span>
<?php
}
?>
我试过
{{ $DriverDetail['IsActive'] }}
并在 {{}}
<span class='account-blocked'></span>
但这是获得 laravel 条件的最佳方式,它相当于我的 php 代码
尝试:
<span class='{{ $DriverDetail['IsActive'] ? 'account-active' : 'account-blocked' }}'></span>
或者,如果您想要分隔整个跨度:
{{ $DriverDetail['IsActive'] ? "<span class='account-active'></span>" : "<span class='account-blocked'></span>" }}
这是使用三元运算符(文档 here). Basically, any value that evaluates to a boolean true will output the first expression (after the '?'), otherwise it outputs the second expression (after the ':'). In this case, the string '1', or even the number 1, evaluates to a boolean true, so the ternary operator will evaluate to the "true" expression ('account-active'). Implicit boolean conversions are covered in the docs here。
试试这个...
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif
使用 blade 模板系统,一个明确的方法是:
@if ($DriverDetail['IsActive'])
<span class='account-active'></span>
@else
<span class='account-blocked'></span>
@endif