Skip to content

[11.x] always alias the Illuminate\Database\Eloquent\Collection#53735

Merged
taylorotwell merged 2 commits into
laravel:11.xfrom
browner12:AB-always-alias-eloquent-collection
Dec 3, 2024
Merged

[11.x] always alias the Illuminate\Database\Eloquent\Collection#53735
taylorotwell merged 2 commits into
laravel:11.xfrom
browner12:AB-always-alias-eloquent-collection

Conversation

@browner12
Copy link
Copy Markdown
Contributor

@browner12 browner12 commented Dec 2, 2024

while there is no behavior change in this commit, my intent behind this is to help prevent stupid mistakes from assuming what Collection is being referenced. by always aliasing this class explicitly, we gain a little confidence when in the code about what version we are referencing.

our use of Illuminate\Support\Collection far outweighs our use of Illuminate\Database\Eloquent\Collection. however, it's very common for both to be used in a file that uses Illuminate\Database\Eloquent\Collection. therefore, I say we treat the base Collection as the default, and our Eloquent Collection as our alias ALL the time. this will provide consistency and help avoid stupid mistakes.

it is also helpful when doing global searches because now we have a unique token to search for.

this idea came to me as I was working on #53726 because making sure I was referencing the correct Collection was the gotcha I had to pay the closest attention to.

while there is no behavior change in this commit, my intent behind this is to help prevent stupid mistakes from assuming what Collection is being referenced. by always aliasing this class explicitly, we gain a little confidence when in the code about what version we are referencing.

our use of `Illuminate\Support\Collection` far outweights our use of `Illuminate\Database\Eloquent\Collection`. however, it's very common for both to be used in a file that uses `Illuminate\Database\Eloquent\Collection`. therefore, I say we treat the base Collection as the default, and our Eloquent Collection as our alias ALL the time. this will provide consistency and help avoid stupid mistakes.

it is also helpful when doing global searches because now we have a unique token to search for.

this idea came to me as I was working on laravel#53726 because making sure I was referencing the correct Collection was the gotcha I had to pay the closest attention to.
@KanekiYuto
Copy link
Copy Markdown

It was the right decision

@taylorotwell taylorotwell merged commit 507f325 into laravel:11.x Dec 3, 2024
@browner12 browner12 deleted the AB-always-alias-eloquent-collection branch December 3, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants