例如在下面的示例代码中:
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();
等等.这样,您可以保持链接范围.