cviebrock / eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel
MIT License
3.91k stars 461 forks source link

Should findBySlugOrFail return Model instead? #596

Closed WalrusSoup closed 1 year ago

WalrusSoup commented 1 year ago

Running into an oddity with larastan, which reports this:

Access to an undefined property Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model::$id.

when calling the function findBySlugOrFail

this function has a docblock which says it can return a collection:

@return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection

however, I don't believe this is capable of returning a collection due to underlying call only returning an instance of a model or throwing:

return static::whereSlug($slug)->firstOrFail($columns);
cviebrock commented 1 year ago

Thanks! Fixed this and it'll go out in the next release.