deligoez / laravel-model-hashid

#️⃣ Generate, Save, and Route Stripe/Youtube-like Hash IDs for Laravel Eloquent Models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined array key 0 when hash id doesn't exist

Falkan3 opened this issue · 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.