我正在使用foreach循环在laravel视图中显示数据。但是循环显示有些问题
控制器
class StudViewController extends Controller {
public function index(){
$studentList = DB::select('select * from student');
// var_dump($studentList);
return view('stud_view',['students'=>$studentList]);
}
} ?>
查看
<!DOCTPE html>
<html>
<head>
<title>View Student Records</title>
</head>
<body>
<table border = "1">
<tr>
<td>Id</td>
<td>First Name</td>
<td>Last Name</td>
<td>City Name</td>
<td>Email</td>
</tr>
@foreach ($students as $student)
<tr>
<td>{{ $student->id }}</td>
<td>{{ $student->first_name }}</td>
<td>{{ $student->last_name }}</td>
<td>{{ $student->city_name }}</td>
<td>{{ $student->email }}</td>
</tr>
@endforeach
</table>
</body>
</html>
任何人都可以帮助我。
谢谢
答案 0 :(得分:0)