我有变量$material_details->pricing=null
我想检查变量是否在laravel刀片文件中设置。我试过
@isset($material_details->pricing)
<tr>
<td>price is not null</td>
</tr>
@endisset
但没有运气。如何在laravel 5.3刀片文件中检查变量是否设置。
你可以简单地做{{ $material_details ?? 'second value' }}
。阅读Elvis和Null合并运算符。
链接:
埃尔维斯:https://en.wikipedia.org/wiki/Elvis_operator
空合并运算符:https://en.wikipedia.org/wiki/Null_coalescing_operator
请尝试以下代码。
@if(is_null($material_details))
// whatever you need to do here
@else
如果变量保持,某些值,您的代码将只打印数据。
尝试以下内容:
@if(isset($material_details->pricing))
<tr>
<td>price is not null</td>
</tr>
@else
<tr>
<td>null</td>
</tr>
@endif
你可以使用laravel三元运算符,如下所示
{!! !empty($material_details->pricing) ? '<tr><td>price is not null</td></tr>' : '<tr><td>Empty</td</tr>' !!}
请试试这个
@if($material_details->pricing != null)
<tr>
<td>price is not null</td>
</tr>
@endif
If are able to access your variable through {{ $material_details['pricing'] }} inside your blade file,
然后这将检查和附加值:
{{ ($material_details['pricing'] == "null") ? "null value" : $material_details['pricing'] }}
要检查和追加元素:
@if($material_details['pricing'] != "null")
<tr>
<td>price is not null</td>
</tr>
@endif