Php 关于雄辩质疑的条件
我需要使用Laravel 5.4显示课程中所有学生的分数,所以我制作了一张这样的表格; 在控制器中:Php 关于雄辩质疑的条件,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我需要使用Laravel 5.4显示课程中所有学生的分数,所以我制作了一张这样的表格; 在控制器中: $courses = Courses::find($id); $marks = Marks::where([ ['course_id','=',$id] ])->orderBy('id','asc')->get(); return view('courses
$courses = Courses::find($id);
$marks = Marks::where([
['course_id','=',$id]
])->orderBy('id','asc')->get();
return view('courses.show', compact('courses','marks'));
他认为:
<table class="table table-hover">
<thead class="text-center">
<th class="text-center">
<b>Alumno</b>
</th>
</thead>
<tbody class="text-left">
@foreach($courses->tests-> as $t)
<tr>
<td>
<b>{{ $t->info->apaterno }} {{ $t->info->amaterno }}, {{ $t->info->name }}</b>
</td>
@foreach($courses->number->pupil as $m)
<td>
Nota {{ $m->mark }}
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
校友
@foreach($courses->tests->as$t)
{{$t->info->apaterno}{{$t->info->amaterno},{{$t->info->name}
@foreach($courses->number->student as$m)
Nota{{$m->mark}
@endforeach
@endforeach
因此,我的问题如下。如果每个分数都属于一个学生,那么我如何才能把考试做得像考试一样,然后列出那么多的分数。当你有关系时,它会起作用,假设在
课程
模型中你有这样的关系:
public function marks()
{
return $this->belongsTo('App\Marks');
}
$courses = Courses::find($id)->with('marks');
然后,您可以使用类似以下内容的快速加载
:
public function marks()
{
return $this->belongsTo('App\Marks');
}
$courses = Courses::find($id)->with('marks');
这将给你的课程与他们相关的分数,而且它是更有效的
有关更多信息,请参阅文档:
希望这能有所帮助。您在模型中定义的关系是什么?课程属于学校/////课程属于数量///课程属于教授///课程有许多测试,而另一个模型Mark具有以下关系:分数属于学校//Mark属于课程//Mark属于学生//Mark属于测试,事实上,我使用的是渴望加载。但是我的问题与循环有关,如何将标记与学生id联系起来,以便在确定的
上显示它,你是在寻找计数,只是为了循环该数量的
?我明白你的意思。但我认为每个测试可能有不同的名称?在分数模型中,每个分数都有一个id、课程id和测试id,在测试模型中,每个测试都有一个id和名称。