首页 > 解决方案 > 打印仪表板中的最后 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()

任何其他解决方案?

标签: laravellaravel-backpack

解决方案


此行将为您提供最后 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>

推荐阅读