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

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

我想在我的主页上显示最新的6个帖子。我正在使用Laravel和Javascript。但我以不同的方式获得布局。我怎样才能在这里展示这些东西。任何的想法。提前致谢。

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 pic

javascript php laravel blade
2个回答
0
投票

如果表中的字段id是自动增量,请尝试此操作

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

0
投票

请试试这些

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

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.