我在db中的表中有几行,每行与三个表相关,每个表都有很多行。当我循环主表行时,我现在也循环三个表行,如果其中一个表有行内容,那么我想阻止显示整个子循环只包含一个值。
在我的控制器中:
public function classWiseResult(Request $request){
$students = Students::where('class',$request->class)
->with('firstTerm')
->with('secondTerm')
->with('finalTerm')
->get();
return view('admin.showResult.show',compact('students'));
}
在我看来:
@foreach($students as $student)
<tr>
<td>{{$student->id}}</td>
<td>{{$student->fname}}</td>
<?php $Ftotal = 0; $Fcount = 0; ?>
@foreach($student->firstTerm as $first)
<?php $Fcount++;?>
<?php $Ftotal += gradePoint($first->number); ?>
@endforeach
<?php $fttp = gpa($Ftotal, $Fcount) ;?>
<td>{{$fttp}}</td>
<td>
@if($Ftotal){
{letterGrade(gpa($Ftotal, $Fcount))}
}
@endif
</td>
结果:
如果我的主题编号低于32
,我想跳过显示结果答案 0 :(得分:1)
此方法使用关系计数比较。
<强>控制器强>
@foreach($students as $student)
@if($student->firstTermPromoted == $student->firstTermAllCount
&& $student->secondTermPromoted == $student->secondTermAllCount
&& $student->finalTermPromoted == $student->finalTermAllCount)
{{ "Promoted" }}
@else
{{ "Not Promoted" }}
@endif
@endforeach
在您的视图中,您可以比较所有关系的总数和通过该条件的关系数。
查看强>
public void createAppiumDriver() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPhone 7 Plus");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "11.2");
capabilities.setCapability("autoWebView", true);
capabilities.setCapability("app", getProperties().getProperty("appURL"));
capabilities.setCapability("autoAcceptAlerts", true);
capabilities.setCapability("useNewWDA", true);
capabilities.setCapability("startIWDP",true);
iosDriver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);}