简体   繁体   English

如何在主页上显示最新的六个帖子(Laravel 5.5)

[英]how to display latest six posts on home page (Laravel 5.5)

I'm want to display latest 6 posts on my homepage.Here I'm using Laravel and Javascript. 我想在首页上显示最新的6条帖子。在这里,我正在使用Laravel和Javascript。 but I'm getting the layout in different way. 但我以不同的方式得到布局。 How can I display those things here. 我如何在这里显示这些东西。 Any idea. 任何想法。 Thanks in Advance. 提前致谢。

post.blade.php post.blade.php

<div class="row">

  <div class="col-lg-4">

    <h2>{{$article->title}}</h2>

    {{ $article->created_at->toFormattedDateString() }}

    <p>{{$article->body}} </p>

    <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>

  </div>

  <div class="col-lg-4">

    <h2>{{$article->title}}</h2>

    {{ $article->created_at->toFormattedDateString() }}

    <p>{{$article->body}} </p>

    <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>

  </div>

  <div class="col-lg-4">

    <h2>{{$article->title}}</h2>

    {{ $article->created_at->toFormattedDateString() }}

    <p>{{$article->body}}</p>

    <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>

  </div>

</div>

index.blade.php index.blade.php

@extends('master')

@section('content')


<div class="container">

    @foreach ($article as $article)

      @include('article.post')

    @endforeach

</div>

@endsection

View 视图

I want to display like view in a pattern but i'm getting a duplicate data. 我想以某种模式显示类似视图,但是我得到了重复的数据。 how can i rectify that View pic 我该如何纠正查看图片

Please try these 请尝试这些

$acticle->orderby('created_at', 'DESC')->take(6)->get()

Thanks 谢谢

如果表acticle中的字段ID是自动增量,请尝试执行此操作

$acticle->orderby('id', 'DESC')->take(6)->get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM