laravel 5.4控制器显示数据库中的所有内容而不是跳过

时间:2017-11-14 02:09:00

标签: php eloquent laravel-5.3 laravel-5.4

您好,感谢您点击此问题/声明。

目标是创建一个"库"显示每个"标题"在数据库中只有一次。我们需要显示21个"标题"只有一次和一个分页。

这是该页面的截图链接https://www.screencast.com/t/euakziNj

这是控制器

CONTROLLER

 return view('library.index')
           ->with('titles', Title::all())
           ->with('first_title', Title::orderBy('created_at', 'desc')->first())
           ->with('second_title', Title::orderBy('created_at', 'desc')->skip(1)->take(1)->get()->first())
           ->with('third_title', Title::orderBy('created_at', 'desc')->skip(2)->take(1)->get()->first());
} 

这是显示标题的页面

{{-- ALL TITLE STORY DISPLAY SECTION --}}
<div class="container-fluid">
    <div class="row medium-padding120 bg-border-color" >
        <div class="container text-center">

              @foreach($titles as $title)      
                <div class="row">
                    <div class="case-item-wrap">
                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                            <div class="case-item" >
                                <div class="case-item__thumb" >
                                    <img src="{{ $title->featured_img }}" alt="{{ $title->name }}" style="width:318px; height:399px;">
                                </div>

                                 <h6 class="case-item__title">
                                   <a href="#">{!! $title->name !!}</a>
                                 </h6>
                                 <h6>{!! str_limit($title->summary, 85) !!}</h6>

                                <a href="">
                                  <button class="btn btn-warning">Read Now</button>
                                </a>
                            </div>
                        </div>



                        <div class="col-lg-4  col-md-4 col-sm-6 col-xs-12">
                            <div class="case-item">
                                <div class="case-item__thumb">
                                    <img src="{{ $second_title->featured_img }}" alt="{{ $second_title->name }}" style="width:318px; height:399px;">
                                </div>

                                  <h6 class="case-item__title">
                                    <a href="#">{!! $second_title->name !!}</a>
                                  </h6>
                                  <h6>{!! str_limit($second_title->summary, 85) !!}</h6>

                                <a href="">
                                  <button class="btn btn-warning">Read Now</button>
                                </a>
                            </div>
                        </div>

                        <div class="col-lg-4  col-md-4 col-sm-6 col-xs-12">
                            <div class="case-item">
                                <div class="case-item__thumb">
                                    <img src="{{ $third_title->featured_img }}" alt="{{ $third_title->name }}" style="width:318px; height:399px;">
                                </div>

                                  <h6 class="case-item__title"><a href="#">{!! $third_title->name !!}</a></h6>
                                  <h6>{!! str_limit($third_title->summary, 85) !!}</h6>

                                <a href="">
                                  <button class="btn btn-warning">Read Now</button>
                                </a>
                            </div>
                        </div>
                    </div>

                </div>
                @endforeach
            </div>

            <div class="padded-50"></div>
        </div>
        </div>
    </div>
</div>

0 个答案:

没有答案