在仪表盘中打印最近5篇文章。

问题描述 投票:0回答:1

我想知道如何把最后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个帖子的功能我放在这里了? 在dashboard方法里面?

$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()

有其他解决办法吗?

laravel backpack-for-laravel
1个回答
1
投票

这一行会让你得到最后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>
© www.soinside.com 2019 - 2024. All rights reserved.