如果客户未选择产品(我是数据库中的布尔值),我试图在视图中显示错误消息。这当前显示消息,但在选定列为真时也会保留。
<?php
$company1 = DB::table('customers')->select('post', 'telans','conum')->where('business', $user )->get();
print_r($company1);
?>
@if (array_filter($company1))
<div class="alert alert-danger" role="alert">
Please <strong><a href="/user_register">click here</a></strong> to select your products</strong>
</div>
@endif
如果有帮助,阵列打印如下:
数组([0] =&gt; stdClass对象([post] =&gt; [telans] =&gt; [conum] =&gt;))
答案 0 :(得分:0)
<强> ANSWER 强>
我需要删除对象stdClass并进行一些调整。
<?php
function checkIsset($val) {
return count(array_filter($val));
}
$company1 = DB::table('customers')->select('post', 'telans','conum')->where('business', $user )->get();
$array = json_decode(json_encode($company1), true);
$filteredArr = array_filter($array, 'checkIsset');
print_r( $array);
//dd($filteredArr);
?>
@if (count(array_filter($filteredArr)) == 0)
@if ( !is_null($company))
<div class="alert alert-danger" role="alert">
Please <strong><a href="/user_register">click here</a></strong> to select your products</strong>
</div>
@endif
@endif