-2
データが入っているテーブルがあります。私はそれを表示しましたが、各行のHistoryボタンをクリックすると、その行のchat_idを取得してコントローラに渡します。これまでは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));
}
@foreach($ chatとしての$ chat)は、私が表示したデータです。ここには、特定の行のchat_idで別のテンプレートを取得するための送信ボタンの履歴があります。 これは他のテンプレートです
Chat History
@foreach($history as $row)あなたのコードに$ chat arayはどこですか?どこに定義されていますか?あなたのテンプレートやコードに定義されていないものをループします。 – MKAD
私は経路内でチャットモデルを取得しています。 Route :: get( 'individual'、function(){ $ chat = Chat :: all(); 戻る:: make( 'chat/individual') - > with( 'chat'、$ chat);}); –