[英]Laravel is and is not empty value check
我知道我们可以检查值是否为空,例如:
@if(!empty(test))
//print results
@endif
但是如果我们要交叉检查2列为空而不为空怎么办?
样品:
我想检查一下: $test->one
和$test->two
$test->one
不为空并且$test->two
为空 = x $test->one
和$test->two
都不为空 = y 我怎么做?
我的代码:
PS:
$test->one
我的样本中的一个等于$order->options_price
$test->two
示例中的$test->two
等于$order->shipment_price
@if(!empty($ order-> product_data))
{{ number_format($order->total_price(), 0) }} @elseif(!empty($order->options_price) && empty($order->shipment_price)) {{ number_format($order->quantity * $order->price + $order->options_price, 0) }} @elseif(!empty($order->options_price) && !empty($order->shipment_price)) {{ number_format($order->quantity * $order->price + $order->options_price + $order->shipment, 0) }} @else {{ number_format($order->quantity * $order->price, 0) }} @endif
问题是我无法获得shipment_price
固定:
我的代码中确实有键入错误。
你可以做
如果$ test-> one不为空并且$ test-> two为空
@if(!empty($test->one) && empty($test->two))
//print results
@endif
如果$ test-> one和$ test-> two都不为空
@if(!empty($test->one) && !empty($test->two))
//print results
@endif
Laravel还提供了blank
助手方法。
来自文档的示例:
blank('');
blank(' ');
blank(null);
blank(collect());
// true
blank(0);
blank(true);
blank(false);
// false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.