【发布时间】:2019-06-07 06:08:09
【问题描述】:
我有一些类似下面的代码,我想问的是完全相同的// dd($example->count()) #10 为什么将dd() 放在每个不同的行上具有不同的值?什么改变了我的$example 事件我从不重新分配它?
$example = $car->wheels()->whereBetween(
'created_at',
[
$starDay->format('Y-m-d h:i:s'),
$today->format('Y-m-d h:i:s')
]
)
$total = $example->count();
// dd($example->count()) #10
$totalSuccess = $example->where('status', 'good')->count();
// dd($example->count()) # 5
$colors = $example->select('color', DB::raw('count(*) as total'))
->groupBy('color')
->get()
->toArray();
// dd($example->count()) # []
【问题讨论】:
-
我猜
count()是一个对象方法。并且每次我们调用count()时都会更改$example对象count属性。这就是我们调用相同的dd($example->count())但返回不同值的原因......
标签: php laravel laravel-5 eloquent