laravel-hashid icon indicating copy to clipboard operation
laravel-hashid copied to clipboard

Can select only necessary columns via `byHash`

Open addeeandra opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Let's say that I had a table with 20 columns. The Model::byHash($hash) is getting all 20 columns by default, and hide columns from $hidden attribute. I often face a scenario where I need to get only 1 or 2 column for a table via Model::byHash($hash).

It's currently achievable with: Model::select('id', 'email')->byHash($hash)->first();. Two problems here:

  1. Loss of type-safety.
  2. Loss of conciseness, we can make it better.

Describe the solution you'd like

Capability to use Model::byHash($hash, $columns), Model::byHashOrFail($hash, $columns)

addeeandra avatar Oct 23 '24 08:10 addeeandra