Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

browner12
Copy link
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

It was the right decision

@taylorotwell taylorotwell merged commit 507f325 into laravel:11.x Dec 3, 2024
40 checks passed
@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