我有我的Laravel application.But簡單的問題我不能找到it.Please的任何解決辦法看到我的代碼在這裏:如何顯示數據庫中的所有行 - Laravel 5.2?
控制器:
public function index(){
$members = Member::paginate(15);
$meal_entry = Member::all();
$breakfast = DB::SELECT("SELECT self_meal_breakfast + guest_meal_breakfast AS breakfast FROM meal_entry");
$lunch = DB::SELECT("SELECT self_meal_lunch + guest_meal_lunch AS lunch FROM meal_entry");
$dinner = DB::SELECT("SELECT self_meal_dinner + guest_meal_dinner AS dinner FROM meal_entry");
$total_meal = DB::SELECT("SELECT self_meal_breakfast + self_meal_lunch + self_meal_dinner + guest_meal_breakfast + guest_meal_lunch + guest_meal_dinner AS total FROM meal_entry");
return view('member.mealView', compact('members','data','breakfast','lunch','dinner','meal_entry','total_meal'));
}
刀片觀點:
<tbody>
<tr>
@foreach($meal_entry as $value)
<td>{{ $value->created_at }}</td>
@endforeach
@foreach($breakfast as $value)
<td>{{ $value->breakfast }}</td>
@endforeach
@foreach($lunch as $value)
<td>{{ $value->lunch }}</td>
@endforeach
@foreach($dinner as $value)
<td>{{ $value->dinner }}</td>
@endforeach
@foreach($total_meal as $value)
<td>{{ $value->total }}</td>
@endforeach
@foreach($meal_entry as $value)
<td>{{ $value->created_at }}</td>
@endforeach
</tr>
</tbody>
和表:meal_entry。
如果有一個row
在數據庫中,然後其確定(see)到view.But當有row
不止一個那麼它在一個row
所有數據(see)節目。如何我可以處理這件事情?我認爲它應該運行另一個循環,但我該怎麼做?提前致謝。
拜託,你能告訴我們該怎麼樣的表看起來像? 謝謝! –
@IdirOuhabMeskine當然... http://prntscr.com/d7whid –
由於數據在一個表中。您應該執行單個查詢。 –