Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

How specific to be with my Model creation?

Hi, I have a more best practices question. I am creating a site where users can create organizers/events and I am running into an interesting question. Normally I would just set up my project so that the name needs to be unique so I can't have Post1 and Post1. However, I'm wondering if that isn't enough for users entering the events. I base my RouteKey off slug and that adds some interesting problems. Suddenly one user can add Post 1 and another can add Post-1 and that passes my validation tests fine but errors out on submission to my database. Also, what if a user adds an event called 'Dinowars' and another enters one called 'Dino Wars'. They are obviously the same event and I don't want them entered twice. How do you deal with this?

0 likes
5 replies
mabdullahsari's avatar

There are many ways to deal with this problem, but the most common one is to suffix the "duplicate" slugs with an integer value starting from 0.

There is a package published by Spatie called

spatie/laravel-sluggable

which can save you lots of repetitive work. Just use it and you are good to go (unless you really want to use your own implementation).

chrisgrim's avatar

Thanks for the quick responses. I will look into both of those things. From what I saw real quick neither of those solutions deals with the problem of 'Dinowars' vs 'Dino Wars'. Would it be worth doing a where() search for LIKE keywords or is that overkill? Thanks

Snapey's avatar
Snapey
Best Answer
Level 122

I handled a similar scenario here (for example)

https://speakernet.co.uk/talk/2037/1-life-do-something-about-it

I include the slug in the URL but also use the talk id so that all URLs are unique even if someone enters a talk with the same name.

I have the SEO benefits with only small visual distraction and don't have the hassle of creating unique slugs.

chrisgrim's avatar

Oh that is a cool way to do it! Even if I can't catch every single case it still will never have an issue with the same url

Please or to participate in this conversation.