Closed felixsc closed 3 years ago
It's not possible right now, but this use case has crossed my mind. I didn't end up needing this functionality at that moment but it can definitely be quite powerful. I'll take a look at this. Thanks for the feedback 😄
So not sure if this fully covers your use case but you can now define the dependency type like this 😄
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('product')
->setPlaceholder('For which product do you want to create a license?')
)
->add(
SpotlightCommandDependency::make('name')
->setPlaceholder('How do you want to name this license?')
->setType(SpotlightCommandDependency::INPUT)
);
It does not call a method at the moment after an "INPUT" dependency is submitted. But you can use the dependency in the execute method:
public function execute(Spotlight $spotlight, Product $product, string $name)
{
// $spotlight->emit('openModal', 'license-create', ['product' => $product->id, 'name' => $name]);
$draft = auth()->user()->drafts()->create(["name" => $name]);
$sptlight->redirectRoute('drafts.edit', $draft);
}
It works perfectly. I can now do exactly what I wanted.
Thank you, Philo!
Is it possible to use the input of a SpotlightCommandDependency to create a new model instead of searching for one?
What I'm trying to do I would like to start with a spotlight command that opens a text input like it does now. But instead of using the input of the dependency as a search query and returning models, I'd just take the string and create a new model.
Start pretty much as it is now:
Then instead of returning a collection of SpotlightSearchResult there would be an action:
As I understand it, right now it'll automatically search for a
searchDrafts
method and expect a collection of SpotlightSearchResult returned. For the above use case, it probably shouldn't call thecreateDraft
method until the user submits what they typed into the input.I understand if it's out of scope for this package & feel free to close the issue.
But I'm curious if it is maybe somehow possible already?