代码之家  ›  专栏  ›  技术社区  ›  derdida

截断Laravel?仅限最新的行

  •  0
  • derdida  · 技术社区  · 7 年前

    我只想获取带有截断的L5.5中最新的行。

    例如,我的桌子是

    ID  Name created
    1   test xxxx-xx-xx
    2   test xxxx-xx-xx
    3   test1 xxxx-xx-xx
    

    现在,我只想获取唯一的行(带名称),但要获取最新创建的行。

    有口才的话可以吗?我正在使用PostgreSQL的数据库。

    1 回复  |  直到 7 年前
        1
  •  1
  •   jfadich    7 年前

    truncate在SQL中有一个非常具体的含义,这不是您想要的。truncate将删除表中的所有记录。

    您需要的是按名称对行进行分组,然后按最新的顺序进行排序。口若悬河

    Model::latest()->groupBy('Name')->get();