从数据库中检索显示每个用户记录的数据-Laravel

I am trying to understand how to retrieve a record from the database which was submitted by a specific user and display that one single record. Currently, I am retrieving all submitted posts with a simple forelse loop. The idea is to display this information in Bootstraps card title view (photo below). Ultimately, as the user posts more content the view layout would look something like this https://getbootstrap.com/docs/4.0/examples/album/

当用户添加更多帖子时,我想全部检索它们,但将每个帖子显示在单个Card标题中,如下所示。谁能帮助我了解此过程,以使其最终起作用?

enter image description here

@foresle循环

@forelse($posts as $post)
    <p><strong>
            <a href="/posts/{{ $post->id }}">{{ $post->title }}</a>
            </strong></p>
@empty
    <p>No Posts Currently</p>
@endforelse 
评论
  • FBI
    FBI 回复

    您可以使用以下代码实现这种类型的视图:

    <div class="row">
        @forelse($posts as $post)
        <div class="col-md-4">
            <div class="card mb-4 box-shadow">
                <img class="card-img-top"
                     src="{{ $post->image }}"
                     data-holder-rendered="true">
                <div class="card-body">
                    <p class="card-text">{{ $post->title }}</p>
                    <div class="d-flex justify-content-between align-items-center">
                        <div class="btn-group">
                            <a href="/posts/{{ $post->id }}" class="btn btn-sm btn-outline-secondary">View</a>
                        </div>
                        <small class="text-muted">9 mins</small>
                    </div>
                </div>
            </div>
        </div>
        @empty
            <p>No Posts Currently</p>
        @endforelse
    </div>