diff --git a/config.php b/config.php index 3288464..27b21a3 100644 --- a/config.php +++ b/config.php @@ -13,5 +13,10 @@ 'hide_methods' => [ 'HEAD', ], - + + /** + * Group routes by prefix. + */ + 'group_by_prefix' => true, + ]; diff --git a/views/partials/item.blade.php b/views/partials/item.blade.php new file mode 100644 index 0000000..d42e6d4 --- /dev/null +++ b/views/partials/item.blade.php @@ -0,0 +1,18 @@ + + + @foreach (array_diff($route->methods(), config('pretty-routes.hide_methods')) as $method) + {{ $method }} + @endforeach + + {{ $route->domain() }} + {!! preg_replace('#({[^}]+})#', '$1', $route->uri()) !!} + {{ $route->getName() }} + {!! preg_replace('#(@.*)$#', '$1', $route->getActionName()) !!} + + @if (method_exists($route, 'controllerMiddleware')) + {{ implode(', ', array_merge($route->middleware(), $route->controllerMiddleware())) }} + @else + {{ implode(', ', $route->middleware()) }} + @endif + + diff --git a/views/routes.blade.php b/views/routes.blade.php index 4005f6f..fcd3900 100644 --- a/views/routes.blade.php +++ b/views/routes.blade.php @@ -31,45 +31,98 @@ table.hide-domains .domain { display: none; } + + ul.routePrefixLinks { + list-style: none; + } + + ul.routePrefixLinks li { + background-color: #3B5998; + float: left; + margin-right:5px; + margin-top: 5px; + padding: 0 5px; + } + + ul.routePrefixLinks li a { + color: #FFF; + } + + td.routePrefixName h5 { + background-color: #edeff0; + padding-left:10px; + } + + td.routePrefixName:hover { + background-color: #edeff0; + } +

Routes ({{ count($routes) }})

+ reduce(function ($arr,$item) { + $arr[] = $item->getPrefix(); + return $arr; + }, collect([]))->reject(null)->unique()->map(function ($value, $key) { + return sprintf('
  • %s
  • ', $value, $value); + })->implode(''); + ?> + + @if ($routePrefixLinks && config('pretty-routes.group_by_prefix')) + + @endif + - - - - - - + + + + + + - 'success', 'HEAD' => 'default', 'POST' => 'primary', 'PUT' => 'warning', 'PATCH' => 'info', 'DELETE' => 'danger']; ?> - @foreach ($routes as $route) + + 'success', 'HEAD' => 'default', 'POST' => 'primary', 'PUT' => 'warning', 'PATCH' => 'info', 'DELETE' => 'danger']; + $lastRoutePrefix = ''; + + $routes = collect($routes)->reduce(function ($arr,$item) { + ( $item->getPrefix() != null ) ? $arr['routesWithPrefix'][]=$item : $arr['routesWithoutPrefix'][]=$item; + return $arr; + },[]); + + $routes['routesWithoutPrefix'] = collect($routes['routesWithoutPrefix'])->sortBy(function ($item, $key) { + return $item->uri()[0]; + }); + ?> + + + @foreach($routes['routesWithoutPrefix'] as $route) + + @include('pretty-routes::partials.item', ['route' => $route]) + + @endforeach + + + @foreach($routes['routesWithPrefix'] as $route) + + @if ($lastRoutePrefix != $route->getPrefix() && config('pretty-routes.group_by_prefix')) - - - - - - + - @endforeach + getPrefix(); ?> + @endif + + @include('pretty-routes::partials.item', ['route' => $route]) + + @endforeach