class Collection extends Collection
Methods
<p>This is done to prevent conflicts when using visibility scopes.</p>
Details
at
line 40
loadAggregate($relations, $column, $function = null)
<p>This is done to prevent conflicts when using visibility scopes.</p>
<p>Without this, we get the following example query when using a visibility scope and eager loading the count of <code>mentionedBy</code>:.</p> <pre><code class="language-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)</code></pre> <p>So by applying an alias on the parent query, we prevent Laravel from auto aliasing the sub-query.</p>