Hello, I'm trying to create a unique slug. However, I wanted to add a unique ID reference generated randomly at the end to avoid problems in case there are more than 1 with the same name. Is this appropriate? Is it considered a best practice?
Generating a unique ID reference at the end of a slug is a common approach for ensuring uniqueness and your implementation using Str::slug and str_pad looks appropriate and should work as expected.
It's important to note that while this approach can help prevent duplicate slugs, it may not be the most user-friendly or SEO-friendly solution. Adding a random string of characters to a slug will make it more difficult for users to remember or type the URL, and it may not be as search engine-friendly as a more descriptive slug. That may not be of particular concern for you, but it's worth noting.
To balance uniqueness with user-friendliness and SEO-friendliness, you could check the uniqueness of the slug against existing slugs in the database and only generate a new one if necessary, without relying on a random string of characters.
@lbecket Let's say the user doesn't have to remember the URL by heart, but you still pointed out something that is important. I will take care to do as you described and apply a unique ID at the end as written in the above mentioned answer.