【问题标题】:Query data in database to show posts查询数据库中的数据以显示帖子
【发布时间】:2020-05-27 17:59:39
【问题描述】:

【问题讨论】:

标签: php mysql laravel


【解决方案1】:

好吧,也许这个问题不清楚,但我试图弄清楚你想要什么。你可以通过在循环中添加一些条件来过滤将显示的内容

@foreach($news as $key => $new)
   @if($key < 2)
     //div with big image class
   @else
     //div with small image class
   @endif
@endforeach

【讨论】:

    【解决方案2】:

    Laravel Blade 允许使用一组有用的变量,例如

    Loop Variable

    循环时,$loop 变量将在循环内可用。该变量提供对一些有用信息的访问,例如当前循环索引以及这是循环中的第一次还是最后一次迭代:

    @foreach($news as $new)
       @if($loop->index < 2)
         //div with big image class
       @else
         //div with small image class
       @endif
    @endforeach
    

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多