2017-10-18 27 views
1

我使用Laravel 5.5,我想從我的視圖頁面查看我的數據庫中的數據(home.blade.php)如何從laravel5.5獲取數據?

<table> 
 
         <tbody> 
 
        @foreach($home as $key => $data) 
 
         <tr> 
 
          <th>{{$data->created_at}}</th> 
 
          <th>{{$data->category}}</th> 
 
          <th>{{$data->reportitle}}</th> 
 
          <th>{{$data->reportdetails}}</th> 
 
          <th>{{$data->seenstat}}</th> 
 
          <th>{{$data->actionstat}}</th> 
 
          <th>{{$data->donestat}}</th> 
 
         </tr> 
 
        @endforeach 
 
         </tbody> 
 
        </table>

在我home.blade.php我有一個空表,我想表明從數據庫五年計劃數據:

Route::get('home', function() { 
 

 
     $fyp = DB::table('reports')->get(); 
 

 
     return view('home', ['fyp' => $fyp]); 
 

 
    });

+4

你通過'$ fyp'變量不是'$ home'。通過'$ fyp'變量循環 –

回答

2

這必須工作(如@Nazmul說):

@foreach($fyp as $data) 
    <tr> 
     <th>{{$data->created_at}}</th> 
     <th>{{$data->category}}</th> 
     <th>{{$data->reportitle}}</th> 
     <th>{{$data->reportdetails}}</th> 
     <th>{{$data->seenstat}}</th> 
     <th>{{$data->actionstat}}</th> 
     <th>{{$data->donestat}}</th> 
    </tr> 
@endforeach