Php 有人能给我解释一下这个拉威尔密码吗?
我有一些如下的代码,我想问的是完全相同的Php 有人能给我解释一下这个拉威尔密码吗?,php,laravel,laravel-5,eloquent,Php,Laravel,Laravel 5,Eloquent,我有一些如下的代码,我想问的是完全相同的//dd($example->count())#10为什么把dd()放在不同的行上有不同的值?什么更改了我的$example事件?我从未重新分配它 $example = $car->wheels()->whereBetween( 'created_at', [ $starDay->format('Y-m-d h:i:s'), $today->format
//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()) # []
由于每次向查询中添加越来越多的不同子句(如
where
),该值都会发生变化。这些调用实际上会更改查询对象本身,并且更改会持续
$example
中有一个查询对象,其中只有wherebeween
子句。它返回数据库中10行的计数where('status','good')
添加到查询中,它将选择范围缩小到5行select(…)
和groupBy()
调用更改$example
查询$example->where(…)
时,您的$example
查询生成器对象现在将具有where
子句。我猜count()
是一个对象方法。每次调用count()
时,都会更改$example
对象count
属性。这就是为什么我们调用相同的dd($example->count())
但返回不同的值的原因。。。