Introduce a More Expressive Syntax for Database Column Aliasing #48881
Unanswered
obrunopolo
asked this question in
Ideas
Replies: 2 comments 1 reply
-
I'd like to have that. However, knowing Taylor Otwell, it probably won't happen. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'll go further. Maybe this could be extended to joins too. Direct Alias in
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In the current implementation, using column aliases in database queries involves utilizing the
DB::raw()
method. While this works, it introduces raw SQL into the query, which can be less readable and expressive.Current Syntax:
Proposed Syntax:
I propose introducing a more intuitive and expressive way to alias database columns directly within the query array, thereby eliminating the need for
DB::raw()
when doing simple column aliasing.This proposed syntax would streamline code by making it easier to read and write, particularly when dealing with multiple aliases or complex queries. It would align well with Laravel's philosophy of clean, elegant code and could potentially be a backwards-compatible change.
Benefits:
DB::raw()
for simple tasksPossible Implementation:
A change in the internal query builder to interpret associative array keys as aliases when building the SQL query.
Beta Was this translation helpful? Give feedback.
All reactions