Closed Hyra closed 3 years ago
You are on the right track, using ->get($slug)
you are still querying for the path.
Try this instead:
$article = $sheets->collection('posts')
->all() // This returns a Collection-instance
->where('slug', $slug)
->first();
You could also look into the route model binding (docs) and bind it with the above resolution-logic.
After writing this I realize your issue is quite old, hopefully you solved it!
Hi @olssonm thanks for your reply.
I ended up solving it like this back then:
$article = $sheets->collection('posts')->all()->first(function ($item) use ($slug) {
return $item->slug === $slug;
});
I like your approach better though, it's a lot cleaner :)
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.
When using a custom pathParser, for instance the default
Spatie\Sheets\PathParsers\SlugWithDateParser
it lists the parsed slugs perfectly.However, when requesting the single version by this slug it won't find it in the collection.
For instance, a post called
2020-01-30.some-post-here.md
and the following sheets config:This will list the
slug
assome-post-here
, but when navigating to/blog/some-post-here
and using the following route:It will result to
null
becauseget
seems to expect the full path again, rather than the parsed slug. Requesting it with/blog/2020-01-30.some-post-here
works fine, but defeats the purpose of the original slug.Am i missing something, or is this intentionally?