laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Eloquent: support "selects" model property to allow for specified column query selection, basically functioning as a global scope "shortcut" #2521

Open marknuyens opened 3 years ago

marknuyens commented 3 years ago

I've stumbled upon a situation where I didn't want to get all columns to be loaded, in my case because some contain BLOB data. I realized there is an Eloquent "hidden" property to achieve the result, however, this only hides the data, not effectively excludes it from the database query.

I also know there are ways to add a global scope, which is what I ended up doing. However, I found it to be generally useful, perhaps even as part of the default Laravel Eloquent model behavior. Please see my demo below:

image

I guess it's a minor feature, but could very well been derived from Eloquent, in my opinion.

Anyway, would love to hear what everyone else thinks...

Thanks!