我的查看页面:
@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
Controller :
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'));
}
我制作了上面显示的 Controller 和 View ,但是当没有数据时我似乎无法弄清楚问题是什么,它仍然显示如下:
我试图让它显示数据,但当没有数据时,它会显示其他内容。
我在dd()时有两个有数据和无数据的例子;
首先是数据:
第二个没有数据:
因此没有数据的应该显示其他内容,例如错误消息。
最佳答案
$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']))
关于php - 如何 if else 显示其他内容 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48676539/