使用foreach循环在刀片中进行数据渲染

问题描述 投票:0回答:1

此代码应列出从数据库到刀片文件的所有缺少的主要内容。数据库查询成功检索到正确的数据,但它不在刀片中呈现?

for($i=0;$i<sizeof($majors_array1);$i++)
{ if (School::where('major', '=', $majors_array1[$i])->exists()) 
{ echo $majors_array1[$i] . '       ' ." found"."<br/>";}
else
{ return view('enter-school-dept')->with('majors_array1', 
$majors_array1[$i]);}
}
<table>
<tr>
<th>Title</th>
<th>School</th></tr>
<tr>
@foreach (majors_array1 as $majors) 
<td>$majors</td>
@endforeach
</tr>
</table>

前CSE EEA

我收到错误:

Use of undefined constant majors_array1 - assumed 'majors_array1' (this will throw an Error in a future version of PHP) (View: C:\xampp\htdocs\test\resources\views\enter-school-dept.blade.php) 
laravel-5.7
1个回答
0
投票

替换你的foreach:

@foreach (majors_array1 as $majors) 
<td>$majors</td>
@endforeach

附:

@foreach ($majors_array1 as $major) 
<td>{{ $major }}</td>
@endforeach
© www.soinside.com 2019 - 2024. All rights reserved.