2017-03-04 64 views
0

我試圖從控制器中傳遞數組,但它不顯示錯誤,因爲它重新確認變量但數據不在那裏,與此同時,當我嘗試dd( )在控制器中,我有數據在那裏。 下面是我的代碼:無法傳遞視圖中的數據(laravel 4)

//控制器

public function showMessage(){ 
    $id = Input::get('recordid'); 

    foreach ($id as $chat_id) { 
     $history = Chat::where('chat_id','=', $chat_id)->get(); 

     return View::make('chat.chatview', compact($history)); 
    } 
} 

//查看

@extends ('master') 
@section ('content') 

<div class="container"> 
    <h1 style="color: white;">Chat History</h1> 
    <?php if (isset($history)) { ?> 
      @foreach($history as $row) 
      <table> 
       <tr> 
        <td><?php echo $history ;?></td> 
       </tr> 
      </table> 
      @endforeach 
    <?php } ?> 
</div> 
@stop 

//路線

Route::get('chathistory', function(){ 
    return View::make('chat/chatview');}); 

的數組,我得到的是從另一種觀點代碼如下: //查看

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

//路線

Route::get('individual', function(){ 
    $chat = Chat::all(); 
    return View::make('chat/individual')->with('chat', $chat);}); 

Route::post('individual','[email protected]'); 

回答

1

更改以下行:

return View::make('chat.chatview', compact($history)); 

return View::make('chat.chatview', ['history' => $history]); 

return View::make('chat.chatview')->with(compact('history')); 

並重試。

+0

這工作,但現在我只能從第一行獲取數據。當我按下狀態按鈕時,它僅適用於第一行,當我嘗試其他任何行時,它不返回任何內容 –

0

更改這裏

return View::make('chat.chatview')->with('history',$history); 
相關問題