单击时通过行获得聊天ID



我有一个填充数据的表。我已经显示了它,但是现在,当我单击每一行的"历史记录"按钮时,以获取该行的chat_id并将其传递给控制器。到目前为止,我正在通过一系列ID,但我无法使其正常工作。

以下是我到目前为止的代码:

//视图

<?php $arr = 0; ?>
    @foreach($chat as $row)
        <tr>
            <td>{{ $row->chat_id }}</td>
            <td>{{ $row->fullname }}</td>
            <td>{{ $row->email }}</td>
            <td>{{ $row->plaintext }}</td>
            <td>{{ $row->transcript_text }}</td>
            <td>{{ $row->duration }}</td>
            <td>
                <button type="submit" name="history" onclick="javascript:getID('{{$row->chat_id}}','{{$arr}}')">History</button>
                <input name="recordid[]" id="recordid[]" type="hidden">
            </td>
        </tr>
        <?php $arr++; ?>
    @endforeach
    <script type="text/javascript">
        function getID(id, arr){
            $('[id^=recordid]').eq(arr).val(id);
        }
    </script> 

//控制器

public function showMessage(){
    $id = Input::get('recordid');
    $history = Chat::where('chat_id','=', $id)->get();
    return View::make('chat.chatview')->with(array('history'=>$history));
}

您的数组名称您给模板的名称是历史记录with(array('history'=>$history));,而不是通过历史记录@foreach($history as $chat)聊天@foreach($chat as $row)循环以获取结果

最新更新