Created
August 26, 2015 13:45
-
-
Save jechav/d80d3b8c0763dc8a1306 to your computer and use it in GitHub Desktop.
Laravel Slug function
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 static function getEventSlug($title) { | |
$slug = Str::slug($title); | |
$slugCount = count( Service::whereRaw("slug REGEXP '^{$slug}(-[0-9]*)?$'")->get() ); | |
return ($slugCount > 0) ? "{$slug}-{$slugCount}" : $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment