Created
September 6, 2019 19:47
-
-
Save marianmirzacu/df15ecfc9cfb5cb5351292a1ab90a2e2 to your computer and use it in GitHub Desktop.
makeSlugFromTitle - Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function makeSlugFromTitle($title) | |
{ | |
$slug = Str::slug($title); | |
$count = Conversation::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count(); | |
return $count ? "{$slug}-{$count}" : $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment