例如在下面的示例代码中:
function crunchNumbersForToday()
{
return $this->crunchSomeinformationInRange(Payments::where('created_at', Carbon::Now()));
}
function crunchNumbersInRange($range)
{
$paymentsToCrunch = Payment::where('state', 'payed')->append($range)->get();
// Work with the payments
}
因此,在这种情况下,created_at字段的where将附加到状态等于payed的查询中.内容如下:where created_at =’2015-07-08 12:00’AND state =已付款.
解决方法:
对于您的代码(在您的付款模型中):
function scopetoday($query)
{
return $query->where('created_at', Carbon::Now());
}
function scopeNumbersInRange($query)
{
return $query->where('state', 'payed');
// Work with the payments
}
Payment::numbersInRange()->today()->get();
编辑:
您也可以使它们动态化:
function scopeDate($query, $date)
{
return $query->where('created_at', $date);
}
…
Payment::numersInRange()->date(Carbon::Now())->get();
等等.这样,您可以保持链接范围.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。