2018-01-25 02:20
浏览 25


I have written a code to view data but I'm having some problems.

From the code, I wrote it's viewing the data from one table which is the $details. But I also wanna view the data from the $detailsAns.

How can I do that? also, can I foreach two data from that two tables?

my code below:

public function queries($companyID, $entityType, $entityValue)
    $data = [];
    $details = DiraQuestion::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();
    $detailsAns = DiraResponses::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();

    foreach($details as $key => $detailsValue)
        if(!array_key_exists($detailsValue->intent, $data))
        $data[$detailsValue->intent] = [];

        if(!array_key_exists($detailsValue->reply, $data[$detailsValue->intent]))
            $data[$detailsValue->intent]['answer'][$detailsValue->reply] = $detailsValue->id;

        if(!array_key_exists($detailsValue->queries, $data[$detailsValue->intent]))
            $data[$detailsValue->intent]['question'][$detailsValue->queries] = $detailsValue->id;

    return view('AltHr.Chatbot.queries', compact('data','entityType','entityValue','companyID'));

so as you can see I can return the data from foreach for $details but now I want to return data for $detailsAns also. how can I do that?

my database structure:

table1: enter image description here

table2: enter image description here

so to get the data it first has to select the company id, eType, eVal, and intent so from that now i need to display the reply and queries.

The output that i want is as below: enter image description here

So as you can see i can output the questions table in the foreach that i did. and if i change the foreach to $detailsAns then i display the reply.. but i want to view the both now

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题