laravel - 打印仪表板中的最后 5 篇文章
问题描述
我想知道如何使用背包将最后 5 个项目的列表放在仪表板中?我做了桌子
<div class="table-responsive">
<table class="table table-hover m-0 table-actions-bar">
<thead>
<tr>
<th>
<div class="btn-group dropdown">
<button type="button" class="btn btn-light btn-xs dropdown-toggle waves-effect waves-light"
data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-chevron-down"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</th>
<th>Titolo Post</th>
<th>Data</th>
<th>Stato</th>
<th>Categria</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
<h5 class="m-0 font-weight-medium"></h5>
</td>
<td>
<i class="mdi mdi-map-marker text-primary"></i>
</td>
<td>
<i class="mdi mdi-clock-outline text-success"></i>
</td>
<td>
<i class="mdi mdi-currency-usd text-warning"></i>
</td>
<td>
<a href="#" class="table-action-btn"><i class="mdi mdi-pencil"></i></a>
<a href="#" class="table-action-btn"><i class="mdi mdi-close"></i></a>
</td>
</tr>
</tbody>
</table>
</div>
我在 jumbotron.blade.php 中制作了表格,然后在屏幕上打印你的功能我把它放在这里的最后 5 个帖子?在仪表板方法中?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
任何其他解决方案?
解决方案
此行将为您提供最后 5 篇文章。
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
您需要将其传递给视图。前任:
return view('dashboard', ['articles' => $articles]);
并循环刀片文件表上的文章。前任:
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
@foreach($articles as $article)
<tr>
<th scope="row">{{ $article->id }}</th>
<td>{{ $article->title }}</td>
<td>{{ $article->author }}</td>
<td>{{ $article->created_at }}</td>
</tr>
@endforeach
</tbody>
</table>
推荐阅读
- python - 如何重新排序字典的动态字符串键以将其保存到 JSON
- swift - How to reflect the new section to UICollectionView in RxDataSource?
- java - How to detect the execution time of StopWatch guava?
- python - How can I add points onto a seaborn barplot?
- postgresql - 如何创建长度在一个字段中的两个数字和另一个字段中的 id 之间的字符串
- visual-studio-2017 - Where are the Azure Functions Local Host Settings
- c++ - c++如何组成原子操作?
- git - 如何从命令行 GIT REWORD?
- android - Android:如何动态设置 TextView 文本大小,以便文本不会换行到下一行
- docker - 无法在 Jenkins 中运行 Groovy sh 命令