laravel刀片文件中检查变量为null [英] checking variable is null in laravel blade file
问题描述
我有变量 $ material_details-> pricing = null
我要检查变量是否在laravel刀片文件中设置.我尝试过
I have the variable $material_details->pricing=null
I want to check the variable is set in laravel blade file.I have tried as
@isset($material_details->pricing)
<tr>
<td>price is not null</td>
</tr>
@endisset
但是没有运气.如何检查laravel 5.3刀片文件中是否设置了变量.
but no luck .How to check the variable is set or not in laravel 5.3 blade file.
推荐答案
您可以使用
空合并运算符: {{$ material_details ??第二个值"}}
或elvis运算符: {{$ material_details?:'默认值'}}
(检查给定值是否为空或空)
or elvis operator: {{ $material_details ?: 'default value' }}
(checks given value is empty or null)
阅读Elvis和Null合并运算符.
Read on Elvis and Null coalescing operator.
链接:
猫王: https://en.wikipedia.org/wiki/Elvis_operator
空合并运算符: https://en.wikipedia.org/wiki/Null_coalescing_operator
这篇关于laravel刀片文件中检查变量为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!