S
foreach ($users as $designer) {
$designers[] = [
'id'=> $designer->id
];
Вывод:
^ array:4 [▼
0 => array:1 [▼
"id" => 109
]
1 => array:1 [▼
"id" => 130
]
2 => array:1 [▼
"id" => 109
]
3 => array:1 [▼
"id" => 130
]
]
Size: a a a
S
foreach ($users as $designer) {
$designers[] = [
'id'=> $designer->id
];
Вывод:
^ array:4 [▼
0 => array:1 [▼
"id" => 109
]
1 => array:1 [▼
"id" => 130
]
2 => array:1 [▼
"id" => 109
]
3 => array:1 [▼
"id" => 130
]
]
P
U
S
S
🎃
🎄P
НК
A
НК
НК
A
public function scopeWithProductsSum(Builder $query): Builder
{
return $this->scopeWithSum($query, 'products', 'amount');
}
public function scopeWithSum(Builder $query, string $relationName, string $fieldName): Builder
{
return $query->withCount([$relationName . ' as ' . $relationName . '_' . $fieldName . '_sum' => function ($query) use ($fieldName) {
$query->select(DB::raw('SUM(`' . $fieldName . '`)'));
}]);
}
НК
public function scopeWithProductsSum(Builder $query): Builder
{
return $this->scopeWithSum($query, 'products', 'amount');
}
public function scopeWithSum(Builder $query, string $relationName, string $fieldName): Builder
{
return $query->withCount([$relationName . ' as ' . $relationName . '_' . $fieldName . '_sum' => function ($query) use ($fieldName) {
$query->select(DB::raw('SUM(`' . $fieldName . '`)'));
}]);
}
A
DB::raw(‘IF(COUNT(`’ . $fieldName . '`) > N, 1, 0)’
A
A
A
public function scopeWithDeletable(Builder $query, $number = 10)
{
return $query->withCount([
'application as application_deletable' => function (Builder $query) use ($number) {
$query->select(DB::raw(sprintf('IF(COUNT(*) > %d, 1, 0', $number)));
}]
);
}
ЕП
$response = $this->get('/');
$response->assertStatus(200);
A
ЕП