class Collection extends Collection

Methods

loadAggregate($relations, $column, $function = null)

This is done to prevent conflicts when using visibility scopes.

Details

loadAggregate($relations, $column, $function = null)

This is done to prevent conflicts when using visibility scopes.

Without this, we get the following example query when using a visibility scope and eager loading the count of `mentionedBy`:. ```sql SELECT `id`, ( SELECT count(*) FROM `posts` AS `laravel_reserved_0` INNER JOIN `post_mentions_post` ON `laravel_reserved_0`.`id` = `post_mentions_post`.`post_id` WHERE `posts`.`id` = `post_mentions_post`.`mentions_post_id` --- ^^^^^^^ this is the problem, visibility scopes always assume the default table name, rather than --- the Laravel auto-generated alias. AND `TYPE` in ('discussionTagged', 'discussionStickied', 'discussionLocked', 'comment', 'discussionRenamed') ) AS `mentioned_by_count` FROM `posts` WHERE `posts`.`id` in (23642) ``` So by applying an alias on the parent query, we prevent Laravel from auto aliasing the sub-query.

Parameters

$relations
$column
$function