2 回答
TA贡献1772条经验 获得超5个赞
为什么用相同的名称调用两个事件。你改变你的代码如下。
studentRegister.php
public function getStudents(){
$students = Student::all();
$msgevents = Event::all()->orderBy('id', 'DESC');
return view('dashboard', [
'students' => $students,
'msgevents' => $msgevents
]);
}
不要忘记use App\Event;在文件中添加。
dashboard.blade.php
<div class="paginate-no-scroll 5">
<div class="items">
@if(count($msgevents) > 0)
@foreach ($msgevents as $msg)
<div>
<svg class="bd-placeholder-img mr-2 rounded" width="24" height="24" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: 32x32"><rect width="30%" height="30%" fill="#007bff"/><text x="50%" y="50%" fill="#007bff" dy=".3em"></text></svg>
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">{{$msg -> title}}</strong> | {{$msg -> deadline}} |<b style="color: #25027f"> @username</b> | <a href="#" style="text-decoration: underline;">Edit</a> | <a href="/delete/{!! $msg -> id !!}" style="text-decoration: underline;">Delete</a><br>
{{$msg -> message}}
</div>
@endforeach
@endif
<table id="tableData" class="table table-bordered table-striped">
<thead>
<th>#</th>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</thead>
@if(count($students) > 0)
@foreach ($students as $std)
<tr>
<td style="text-align:center"><img src="uploads/{{$std->image}}" style="width: 50px;height: 50px; border-radius: 50%" alt="{{$std->image}}"></td>
<td style="text-align:center; padding-top: 25px;" >{{$std->studentID}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->fName}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->surName}}</td>
<td style="text-align:center; padding-top: 25px;"><a href="" class="btn btn-primary"> view</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
TA贡献1963条经验 获得超6个赞
您在控制器中使用具有相同with变量的相同视图。dashboard
在 EventController.php getEvent 中:
return view('dashboard') -> with('dashboard', $msgevent);
在 studentRegister.php getStudents 中:
return view('dashboard') -> with('dashboard', $Students);
在各自的文件中将它们更改为更合适的名称,例如:
return view('dashboard') -> with('events', $msgevent);
return view('dashboard') -> with('students', $Students);
然后在您的blade文件中使用这些名称,例如:
<div class="paginate-no-scroll 5">
<div class="items">
@if($events && count($events) > 0)
@foreach ($events as $msg)
<div>
<svg class="bd-placeholder-img mr-2 rounded" width="24" height="24" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: 32x32">
<rect width="30%" height="30%" fill="#007bff"/>
<text x="50%" y="50%" fill="#007bff" dy=".3em"></text>
</svg>
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">{{$msg -> title}}</strong> | {{$msg -> deadline}} |<b
style="color: #25027f"> @username</b> | <a href="#" style="text-decoration: underline;">Edit</a> |
<a href="/delete/{!! $msg -> id !!}" style="text-decoration: underline;">Delete</a><br>
{{$msg -> message}}
</div>
@endforeach
@endif
<table id="tableData" class="table table-bordered table-striped">
<thead>
<th>#</th>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</thead>
@if($students && count($students) > 0)
@foreach ($students as $std)
<tr>
<td style="text-align:center"><img src="uploads/{{$std->image}}" style="width: 50px;height: 50px; border-radius: 50%" alt="{{$std->image}}"></td>
<td style="text-align:center; padding-top: 25px;">{{$std->studentID}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->fName}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->surName}}</td>
<td style="text-align:center; padding-top: 25px;"><a href="" class="btn btn-primary"> view</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
- 2 回答
- 0 关注
- 88 浏览
添加回答
举报