dsp1836 2014-07-17 00:04
浏览 41
已采纳

使用Laravel查询构建器仅选择第一个单元格中的第一个单元格

Is there a method to select a first row cell in Laravel's query builder? Im looking for something like this:

$my_value = DB::table("my_table")
    ->select("value")
    ->where("key", "=", "my_key")
    ->getFirstRowCellValueOnly()

Yea, I could do it by selecting first row and then just selecting key "value" from returned array (->first()["value"]), but a default method would be more tidier ^ ^.

  • 写回答

1条回答 默认 最新

  • dongtuota3633 2014-07-17 00:23
    关注

    Yup, the method is called pluck().

    $my_value = DB::table("my_table")
        ->select("value")
        ->where("key", "=", "my_key")
        ->pluck("value"); // same as in the select
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部