【发布时间】:2020-05-03 07:15:25
【问题描述】:
你好,这段代码可以重构吗?
public function all(array $attributes)
{
$rates = $this->model->query()->where([
['able_type', $attributes['type']],
['able_id', $attributes['type_id']]
])
->get(['rate']);
return [
'count' => $rates->count(),
'average' => $rates->avg('rate')
];
}
public function show($attributes)
{
$result = $this->model->query()->where([
['user_id', $attributes['user_id']],
['able_type', $attributes['type']],
['able_id', $attributes['type_id']]
])
->first();
return $result;
}
where语句可以写成不需要重复的吗?
【问题讨论】:
标签: php laravel repository-pattern