Laravel
2
Вклад в тег
public static function getProviderByTotalParams()
{
$mainTable = self::tableName();
$sql = '
SELECT m_departments.id, m_departments.name,
COUNT(m_news.id) + COUNT(m_posts.id) + COUNT(m_forums.id) + COUNT(m_questions.id) AS total_count
FROM m_departments
LEFT JOIN m_news ON m_departments.id = m_news.department_id
LEFT JOIN m_posts ON m_departments.id = m_posts.department_id
GROUP BY m_departments.id
ORDER BY total_count DESC
LIMIT 5
';
$dataProvider = new SqlDataProvider([
'sql' => $sql,
'totalCount' => 5,
'pagination' => [
'pageSize' => 5,
],
]);;
return $dataProvider;
}