Skip to content

Commit 551e054

Browse files
author
Andrey Helldar
authored
Merge pull request #2 from TheDragonCode/1.x
Added the ability to exclude route groups
2 parents ed174b2 + 89821e9 commit 551e054

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

src/Helpers/Name.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function resolve(string $uri): Collection
2424
->rtrim(' /')
2525
->explode('/')
2626
->filter(fn (string $value) => $this->has($value))
27-
->map(fn (string $value) => $this->map($value));
27+
->map(fn (string $value) => $this->map($value));
2828
}
2929

3030
protected function getMethodSuffix(array $methods, string $uri): string

src/Routing/Route.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,36 @@
66

77
use DragonCode\LaravelRouteNames\Facades\Name;
88
use Illuminate\Routing\Route as BaseRoute;
9+
use Illuminate\Support\Str;
910

1011
class Route extends BaseRoute
1112
{
13+
protected array $protected_routes_names = [
14+
'_debugbar.*',
15+
'_ignition.*',
16+
'horizon.*',
17+
'pretty-routes.*',
18+
'telescope.*',
19+
];
20+
1221
public function getName(): ?string
1322
{
14-
return Name::get($this->methods(), $this->uri());
23+
return $this->isProtectedRouteName()
24+
? $this->getProtectedRouteName()
25+
: Name::get($this->methods(), $this->uri());
26+
}
27+
28+
protected function isProtectedRouteName(): bool
29+
{
30+
if ($name = $this->getProtectedRouteName()) {
31+
return Str::is($this->protected_routes_names, $name);
32+
}
33+
34+
return false;
35+
}
36+
37+
protected function getProtectedRouteName(): ?string
38+
{
39+
return parent::getName();
1540
}
1641
}

tests/Concerns/Routes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,13 @@ protected function resourceRoutes(Router $router): void
109109

110110
$router->apiResource('resources/comments', ApiResourceController::class);
111111
}
112+
113+
protected function protectedRoutes(Router $router): void
114+
{
115+
$router->get('routes', [Controller::class, 'prettyRoutesList'])->name('pretty-routes.list');
116+
$router->get('routes', [Controller::class, 'prettyRoutesClear'])->name('pretty-routes.clear');
117+
118+
$router->get('telescope/{view?}', [Controller::class, 'telescopeShow'])->name('telescope.show');
119+
$router->get('telescope/telescope-api/views/{telescopeEntryId}', [Controller::class, 'telescopeViewsShow'])->name('telescope.telescope-api.views.show');
120+
}
112121
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Routes;
6+
7+
use Tests\TestCase;
8+
9+
class ProtectedRoutesTest extends TestCase
10+
{
11+
public function testWeb(): void
12+
{
13+
$this->assertSame('pretty-routes.list', $this->getRouteName('prettyRoutesList'));
14+
$this->assertSame('pretty-routes.clear', $this->getRouteName('prettyRoutesClear'));
15+
16+
$this->assertSame('telescope.show', $this->getRouteName('telescopeShow'));
17+
$this->assertSame('telescope.telescope-api.views.show', $this->getRouteName('telescopeViewsShow'));
18+
}
19+
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function defineWebRoutes($router)
5353
$this->basicRoutes($router);
5454
$this->collisionRoutes($router);
5555
$this->mixedCases($router);
56+
$this->protectedRoutes($router);
5657
$this->routesWithMultiParameters($router);
5758
$this->routesWithParameters($router);
5859
}

0 commit comments

Comments
 (0)