简体   繁体   中英

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. but I'm getting the layout in different way. How can I display those things here. Any idea. Thanks in Advance.

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

@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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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