duanmibei1929
2016-11-16 08:37
浏览 27
已采纳

如何显示数据库中的所有行 - Laravel 5.2?

I have simple issue with my Laravel application.But i can not find any solution of it.Please see my code here:

controller:

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'));
}

blade view:

<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>

And the table: meal_entry.

If there is a one row in the database then its ok ( see ) to view.But when there is row more than one then its show in one row with all data( see ).How can i handle this things? I think it should be run another loop but how can i do that? Thanks in advance.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题