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

brainlabs2010's avatar

@KamalKhan

Reply: you are right

@brainlabs2010 You might want to be careful with that because a slug should be unique (at least thats the intended use case). If two titles match, the slug will be the same and cause an sql error.

But if a UNIQUE slug isn't required, then your solution is totally fine.

If it's me i keep the slug column unique and do a unique validation on the post while creating before doing so.

or better i use the eloquent-sluggable package which takes care of slug part as it takers care if a slug is already exists it appends -{n} where n being a unsigned integer value.

Thanks.

Previous

Please or to participate in this conversation.