-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[Request] Extend Eloquent plurality to hasMany() #89
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
Comments
What do you mean? You mean you want to do this?
|
Yep, that's it. Probably just my Rails side leaking over, but it would "feel" more right to me. |
I kind of feel silly agreeing with this but this has always bugged me as well. Not top priority of course. |
-1. I think that's too much magic, too easy to break, and useless with namespaces for model classes. |
👎 |
1 similar comment
👎 |
Ah didn't think about namespaced models yeah. |
I never li 8000 ke using a class name as a string. I would much rather use: return $this->hasMany(Subscriber::class()); Now it is clear that a Model is being referred to, and you can also forget to specify the namespace, as now PHP will do that for you. It's a pity PHP doesn't implement the public static function class()
{
return get_called_class();
} This can also be done with routing: Route::get('home/test', HomeController::at('test')); Automatic namespace resolution and early errors (class does not exists maybe) are the biggest benefits of this approach. |
@JoostK I am confused. You still have to import the class. And not unlike with |
For me it's just clearer. Importing is only necessary once per file, then you're good to go for multiple statements. Also, models are mostly all in the same namespace, so you don't even have to import the namespace/class and it will automatically be correct when e.g. the namespace changes. With just as string you don't have that benefits. As it just generates a string you can still use a string directly, if you want though. |
Yeah, it's always just been the model name. Think it would be more confusing to switch at this point. |
Thanks for the clarification, @JoostK. Makes sense now. |
Obviously not a game-breaker, but Eloquent's smart plurality does not extend to hasMany(), which just feels awkward gramatically. Example:
The text was updated successfully, but these errors were encountered: