wire-elements / spotlight

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
MIT License
911 stars 71 forks source link

Use command name instead of class name when creating a command ID #95

Closed Nublust closed 1 year ago

Nublust commented 1 year ago

This PR derives the ID of a command from the command name instead of the class name. #43 presented the idea of adding the same command multiple times with different parameters, however, this does not work due to the ID being the same in every instance. They register fine, but only one is ever callable.

Happy to change this if there are any more thoughts on how to create a unique ID! I presume command names would normally be unique, though.

PhiloNL commented 1 year ago

Thanks for the PR. This seems to be a breaking change, I would suggest simply overriding the id in your command class if you need a unique id, for example:

class Logout extends SpotlightCommand
{
    protected string $name = 'Logout';

    protected string $description = 'Logout out of your account';

    public function getId(): string
    {
        return md5($this->name);
    }
}