Static table name for models #52485
Unanswered
yanickrochon
asked this question in
Ideas
Replies: 2 comments 4 replies
-
what's wrong with the query you get from the model? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi. Nothing stops you from declaring it static and on construct setting it from the static. Why introduce breaking change for all? |
Beta Was this translation helpful? Give feedback.
3 replies
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.
-
While implementing a method using raw SQL queries to perform a complex database task, I was looking to get the models' table names instead of writing them in clear.
My option was to either:
"notifications"
Notification::make()->getTable()
Neither solution seem OK to me.
Current implementation
After looking at the code, located in
vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
, I found the implementation:and wondered why this could not be static. As in:
Example
The following example illustrates the feasability of the implementation:
Conclusion
This idea not only preserves the existing behavior
but enables direct static calls
Notification::getTableName();
Beta Was this translation helpful? Give feedback.
All reactions