kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

"Integrity constraint violation: 1062 Duplicate entry" if generated slug is not unique #54

Closed oschettler closed 7 years ago

oschettler commented 8 years ago

The $attempts variable in generateTitleSlug() is not appended properly to the $titleSlug.

I avoid duplicate slugs by having a loop in my application code:

// Loop until a unique slug could be generated
$saved = false;
do {
    try {
        $saved = $user->save();
    }
    catch (\Illuminate\Database\QueryException $e);
}
while (!$saved);

This loop never finishes.

kirkbushell commented 7 years ago

@oschettler - do you plan on doing a PR for this by any chance?

kirkbushell commented 7 years ago

@oschettler ?