Add ability for SpotlightResult->when(...) #118
nick-wilkins
started this conversation in
Ideas
Replies: 1 comment
-
Hey @nick-wilkins, The Collection has a when method so you could do something like: Spotlight::registerQueries(
SpotlightQuery::asDefault(function ($query) {
$user = request()->user();
$pages = collect();
$pages->when($user, fn($c) => $c->push(SpotlightResult::make(...)));
}); Would that work? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Some of my SpotlightResult::make commands I only want to register if the user is logged in. At the moment I am having to add an Auth::check() inside the SpotlightQuery::forMode (or token / default), and create 2 separate collections (some with repeated results).
I can refactor slightly of course to create common objects then create the collection afterwards, but it would be nice to have an:
->when(...) option, ie:
SpotlightResult::make()
->when(Auth::check())
->setTitle('Documentation')
...
If this already exists, or some form of, apologies but I can't see it (using Pro FYI)
Beta Was this translation helpful? Give feedback.
All reactions