【问题标题】:Get desired Data from pivot Table从数据透视表中获取所需数据
【发布时间】:2022-07-21 17:10:05
【问题描述】:

我有三个模型,一个是数据透视表(grade_studentattendances),另一个模型是(grades and studentattendances)。我只想显示学生从一年级到八年级的数据。

我的查看代码是:

 <table border="1">
  <tr>
    <th>Id</th>
    <th>Full name</th>
    <th>Roll no</th>
    <th>Date</th>
    <th>Status</th>
    <th>Grade</th>
  </tr>
  @php
    $i=1;
  @endphp
  @foreach($studentattendance as $item) 
  @php $grades=$item->Grade; @endphp
  <tr>
    <th>{{$item->id }}</th>
    <th>{{$item->name}} </th>
    <th>{{$item->roll_no}}</th>
    <th>{{$item->date}}</th>
    <th>{{$item-> status}}</th>
    <th>
    @foreach($grades as $grade)      
      {{$grade->class_name }}
    @endforeach
    </th>
   </tr>
   @endforeach
</table>

我的控制器是:

public function sattend()
    {
        $studentattendance=studentattendance::all();
        return view('primaryhead.s_attend',compact('studentattendance')); 
    }

我只是想以表格的形式显示一年级到八年级的学生

【问题讨论】:

    标签: php mysql laravel pivot-table


    【解决方案1】:
    public function sattend()
        {
            $studentattendance=studentattendance::whereBetween('grade', [1, 8])
            return view('primaryhead.s_attend',compact('studentattendance')); 
        }
    

    【讨论】:

    • 现在什么都不显示了
    • 我不知道您的真实列名更改等级为您的真实列名。
    猜你喜欢
    • 2016-11-21
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2017-07-25
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多