douan5151 2016-12-21 18:46
浏览 23
已采纳

Laravel Eloquent计算价值

I have a column in my table called date which is of type TIMESTAMP.

I am trying to add a very simply scope which will return all results that have a date of tomorrow.

I think I want to be able to do something like this:

public function scopeTomorrow($query)
{
    return $query->where('date', function ($date) {
        return \Carbon\Carbon::parse($date)->isTomorrow();
    });
}

But the $date variable is currently just the query builder.

How can I create a where statement which accepts the value and perfroms some sort of check on it?

  • 写回答

2条回答 默认 最新

  • duanfuxing2212 2016-12-21 18:52
    关注

    You can do this:

    return $query->where('date', '>=', Carbon::tomorrow())
                 ->where('date', '<=', Carbon::tomorrow()->endOfDay());
    

    Or:

    return $query->whereBetween('date', [Carbon::tomorrow(), Carbon::tomorrow()->endOfDay()]);
    

    Also, probably you want to add date to $dates variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用