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

Undefined array key 0 when hash id doesn't exist

Open Falkan3 opened this issue 8 months ago • 0 comments

When trying to find a model using a hash id that doesn't exist, this exception is thrown:

Undefined array key 0

image

The function that is called can return the following values:

@return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null

Which is then accessed:

return $generator->decode($hashIdInstance->hashIdForKey)[0];

When a model can't be found, I suggest a null being returned instead.

Falkan3 avatar Nov 07 '23 18:11 Falkan3