dongshenyu4638 2019-01-27 13:00
浏览 80
已采纳

如何在Laravel进行一年中的独特检查

Here is a table named installments which has date_of_receipt and user_id columns. I need to check if a date date_of_receipt = 27-01-2019 has present according to a user so I have to validate this entity already exists here for any January 2019 day. How can I do that in Laravel5.7 with MySQL?

  • 写回答

1条回答 默认 最新

  • duanmei1922 2019-01-27 13:11
    关注

    Because you are storing it as a string in a particular format, you could achieve this with something like this:

    $start = \Carbon\Carbon::parse($request->date_of_receipt)->startOfMonth()->format('d-m-Y');
    $end   = \Carbon\Carbon::parse($request->date_of_receipt)->endOfMonth()->endOfDay()->format('d-m-Y');
    
    return DB::table('installments')
        ->where('user_id', $user_id)
        ->whereBetween('date_of_receipt', [$start, $end])
        ->exists();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊