dqppv86022 2018-02-08 02:29
浏览 79
已采纳

如何以其他方式展示其他laravel

my view page:

@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'));
    }

I made the controller and view shown above, but I can't seem to figure out what the problem is when there is no data it still shows like this:

enter image description here

I am trying to have it show the data but when there isn't data then for it to show something else.

I have two examples of with and without data when I dd();

first with data:

with

second without data:

without

so the one without data should shows something else like an error message.

</div>
  • 写回答

2条回答 默认 最新

  • doushi1473 2018-02-08 03:06
    关注

    $data is not empty in both cases, you need to be checking the answer index:

    @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
    

    edit

    You've also got an empty string index wrapping both answer and question so

    @if(empty($data['']['answer']))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)