Skip to content

Instantly share code, notes, and snippets.

@jechav
Created August 26, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jechav/d80d3b8c0763dc8a1306 to your computer and use it in GitHub Desktop.
Save jechav/d80d3b8c0763dc8a1306 to your computer and use it in GitHub Desktop.
Laravel Slug function
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