ash-jc-allen / short-url

A Laravel package for creating shortened URLs for your web apps.
MIT License
1.24k stars 156 forks source link

Change behaviour to return existing url by default if exists in database. #112

Closed prog-24 closed 2 years ago

prog-24 commented 2 years ago

Currently, builder will fail if the short url already exists, this behaviour is not idea because it forces you to have extra boiler plate code to use the package when a simple check can resolve this within the package. You can set a flag to throw the exception or add it is a configuration value.

I am referring to these:

Builder.php L:449
        $this->setOptions();

        $this->checkKeyDoesNotExist();

        $shortURL = $this->insertShortURLIntoDatabase();

        $this->resetOptions();
ash-jc-allen commented 2 years ago

Hey, thanks for getting in touch! 😄

I think I'm against the idea of returning a URL if it already exists in the database with a matching key. My main reason for this is that the existing short URL's data will likely be different to the data that you're trying to set for your new URL.

As it stands at the moment, the package is intended to only support one URL per short URL key. This is intentional because the short URL key is the unique identifier for each row in the short_urls table.