Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@
},
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"DragonCode\\LaravelRouteNames\\ServiceProvider"
]
}
}
}
15 changes: 15 additions & 0 deletions config/route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

return [
'names' => [
'exclude' => [
'_debugbar.*',
'_ignition.*',
'horizon.*',
'pretty-routes.*',
'telescope.*',
],
],
];
15 changes: 6 additions & 9 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

class Route extends BaseRoute
{
protected array $protected_routes_names = [
'_debugbar.*',
'_ignition.*',
'horizon.*',
'pretty-routes.*',
'telescope.*',
];

public function getName(): ?string
{
return $this->isProtectedRouteName()
Expand All @@ -28,7 +20,7 @@ public function getName(): ?string
protected function isProtectedRouteName(): bool
{
if ($name = $this->getProtectedRouteName()) {
return Str::is($this->protected_routes_names, $name);
return Str::is($this->getProtectedRouteNames(), $name);
}

return false;
Expand All @@ -38,4 +30,9 @@ protected function getProtectedRouteName(): ?string
{
return parent::getName();
}

protected function getProtectedRouteNames(): array
{
return config('route.names.exclude');
}
}
40 changes: 40 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames;

use Illuminate\Support\ServiceProvider as BaseServiceProvider;

class ServiceProvider extends BaseServiceProvider
{
public function boot(): void
{
$this->publishConfig();
}

public function register(): void
{
$this->registerConfig();
}

protected function publishConfig(): void
{
$this->publishes([
$this->getPath() => config_path('route.php'),
], 'config');
}

protected function registerConfig(): void
{
$this->mergeConfigFrom(
$this->getPath(),
'route'
);
}

protected function getPath(): string
{
return __DIR__ . '/../config/route.php';
}
}
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Tests;

use DragonCode\LaravelRouteNames\Application;
use DragonCode\LaravelRouteNames\ServiceProvider;
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
use Illuminate\Support\Facades\Route as RouteFacade;
use Orchestra\Testbench\Bootstrap\LoadConfiguration as OrchestraLoadConfiguration;
Expand All @@ -29,6 +30,11 @@ abstract class TestCase extends BaseTestCase
{
use Routes;

protected function getPackageProviders($app): array
{
return [ServiceProvider::class];
}

protected function resolveApplication()
{
return tap(new Application($this->getBasePath()), function ($app) {
Expand Down