Skip to content

Instantly share code, notes, and snippets.

@apit
Forked from dwightwatson/RouteClass.php
Last active August 29, 2015 14:07
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 apit/2fc128525a774d6e079b to your computer and use it in GitHub Desktop.
Save apit/2fc128525a774d6e079b to your computer and use it in GitHub Desktop.
<?php
public function routeClass()
{
$routeArray = Str::parseCallback(Route::currentRouteAction(), null);
if (last($routeArray) != null) {
// Remove 'controller' from the controller name.
$controller = str_replace('Controller', '', class_basename(head($routeArray)));
// Take out the method from the action.
$action = preg_replace('/^(get|post|put|delete|patch)/i', '', last($routeArray));
return Str::slug($controller . '-' . $action);
}
return 'closure';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment