我的观看页面:
@if(empty($data))
<p>No response have been attached to this entities.</p>
@else
<p>By default, it will respond with the predefined phrases. Use the form below to customize responses.</p>
@endif
控制器:
public function queries($companyID, $entityType, $entityValue)
{
$data = [];
$details = DiraQuestion::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();
foreach ($details AS $datum)
{
if (!isset($data[$datum->intent])) $data[$datum->intent] = ['question' => [], 'answer' => []];
$data[$datum->intent]['question'][$datum->queries] = $datum->id;
}
$detailsAns = DiraResponses::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();
foreach ($detailsAns AS $datum)
{
if (!isset($data[$datum->intent])) $data[$datum->intent] = ['question' => [], 'answer' => []];
$data[$datum->intent]['answer'][$datum->reply] = $datum->id;
}
ksort($data);
return view('AltHr.Chatbot.queries', compact('data','entityType','entityValue','companyID'));
}
我制作了上面显示的控制器和视图,但我似乎无法弄清楚当没有数据时它仍然显示的问题:
我试图让它显示数据,但是当没有数据时,它就会显示其他内容。
当我dd();
时,我有两个有和没有数据的例子首先是数据:
秒没有数据:
所以没有数据的那个应该显示其他类似错误信息。
答案 0 :(得分:0)
因为你使用empty()函数来检查数据,但是在控制器$ data中是数组,所以它总是不为空。 您可以将empty()函数更改为count()函数。如果$ data为空或为null,则它将等于零。
@if(count($data)==0)
<p>No response have been attached to this entities.</p>
@else
<p>By default, it will respond with the predefined phrases. Use the form below to customize responses.</p>
@endif
&#13;
答案 1 :(得分:0)
$data
都不为空,您需要检查answer
索引:
@if(empty($data['answer']))
<p>No response have been attached to this entities.</p>
@else
<p>By default, it will respond with the predefined phrases. Use the form below to customize responses.</p>
@endif
修改强>
您还有一个包含answer
和question
的空字符串索引,所以
@if(empty($data['']['answer']))