在仪表板中打印最后 5 篇文章
print the last 5 articles in the dashboard
我想知道如何使用背包将最后 5 项的列表放入仪表板?
我做了 table
<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 中创建了 table,然后在屏幕上显示我放在这里的最后 5 个帖子的功能?在仪表板方法中?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
还有其他解决方案吗?
此行将为您获取最后 5 篇文章。
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
您需要将其传递给视图。例如:
return view('dashboard', ['articles' => $articles]);
并循环 blade 文件 table 上的文章。例如:
<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>
我想知道如何使用背包将最后 5 项的列表放入仪表板? 我做了 table
<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 中创建了 table,然后在屏幕上显示我放在这里的最后 5 个帖子的功能?在仪表板方法中?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
还有其他解决方案吗?
此行将为您获取最后 5 篇文章。
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
您需要将其传递给视图。例如:
return view('dashboard', ['articles' => $articles]);
并循环 blade 文件 table 上的文章。例如:
<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>