Since the Slug::fromId() algorithm doesn't produce unique slugs, this adds in a uniqueness check that will attempt to generate a new random slug instead.
I've added in a limit of 10 attempts, to avoid a potential 100+ loop slug search, which would slow down the process a fair bit. I think it's better to notify the developer that there are issues with slugs - which should only happen for a really large dataset.
I added the Slug::random() helper to generate truly random slug values. I based it off the Laravel str_random() code, with the additional limitation of only a-zA-Z.
It would be good to refactor fromId() out, as all it does is generate random slugs that aren't linked to id anyway. Also the use of md5() and uniqid() make it relatively insecure via brute-force guesswork.
Since the
Slug::fromId()
algorithm doesn't produce unique slugs, this adds in a uniqueness check that will attempt to generate a new random slug instead.I've added in a limit of 10 attempts, to avoid a potential 100+ loop slug search, which would slow down the process a fair bit. I think it's better to notify the developer that there are issues with slugs - which should only happen for a really large dataset.
I added the
Slug::random()
helper to generate truly random slug values. I based it off the Laravelstr_random()
code, with the additional limitation of onlya-zA-Z
.It would be good to refactor
fromId()
out, as all it does is generate random slugs that aren't linked toid
anyway. Also the use ofmd5()
anduniqid()
make it relatively insecure via brute-force guesswork.