PHP code example of onamfc / laravel-route-visualizer

1. Go to this page and download the library: Download onamfc/laravel-route-visualizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onamfc / laravel-route-visualizer example snippets


return [
    // Enable/disable the visualizer (auto-disabled in production)
    'enabled' => env('ROUTE_VISUALIZER_ENABLED', app()->environment(['local', 'testing'])),
    
    // Route prefix for the visualizer dashboard
    'route_prefix' => 'route-visualizer',
    
    // Middleware to apply to visualizer routes
    'middleware' => ['web'],
    
    // Cache settings for performance
    'cache' => [
        'enabled' => true,
        'ttl' => 3600, // 1 hour
        'key' => 'route_visualizer_data',
    ],
    
    // Visualization library and options
    'visualization' => [
        'layout' => 'hierarchical', // hierarchical, network
        'pagination' => [
            'enabled' => true,
            'per_page' => 50,
        ],
    ],
    
    // Export settings
    'export' => [
        'path' => storage_path('app/route-maps'),
        'formats' => ['html', 'json', 'svg'],
        'templates' => ['default', 'minimal', 'detailed'],
    ],
    
    // Security settings
    'security' => [
        'hide_sensitive_routes' => true,
        'sensitive_patterns' => [
            'admin/*',
            'api/admin/*',
            '*/password/*',
            'telescope/*',
            'horizon/*',
        ],
    ],
    
    // Validation settings
    'validation' => [
        'check_duplicates' => true,
        'check_missing_controllers' => true,
        'check_missing_methods' => true,
    ],
    
    // Integration settings
    'integrations' => [
        'telescope' => [
            'enabled' => class_exists(\Laravel\Telescope\TelescopeServiceProvider::class),
            'base_url' => '/telescope',
        ],
    ],
];

use onamfc\LaravelRouteVisualizer\Services\RouteScanner;

class YourController extends Controller
{
    public function analyzeRoutes(RouteScanner $scanner)
    {
        // Get all routes with validation
        $routes = $scanner->scanRoutes();
        
        // Get routes grouped by controller
        $byController = $scanner->getRoutesGroupedByController();
        
        // Get routes grouped by middleware
        $byMiddleware = $scanner->getRoutesGroupedByMiddleware();
        
        // Get routes grouped by domain
        $byDomain = $scanner->getRoutesGroupedByDomain();
        
        // Get routes grouped by namespace
        $byNamespace = $scanner->getRoutesGroupedByNamespace();
        
        // Find duplicate routes
        $duplicates = $scanner->findDuplicateRoutes();
        
        // Get hierarchical tree data
        $treeData = $scanner->getTreeData();
        
        // Clear cache
        $scanner->clearCache();
        
        return response()->json($routes);
    }
}

// In your AppServiceProvider
View::composer('route-visualizer::export.html', function ($view) {
    $view->with('customData', 'Your custom data');
});

'security' => [
    'hide_sensitive_routes' => true,
    'sensitive_patterns' => [
        'admin/*',
        'api/admin/*',
        '*/password/*',
        'telescope/*',
        'horizon/*',
        'nova/*',
    ],
],

'middleware' => ['web', 'auth', 'admin'],

'cache' => [
    'enabled' => true,
    'ttl' => 3600, // 1 hour
],

'visualization' => [
    'pagination' => [
        'enabled' => true,
        'per_page' => 50,
    ],
],

'validation' => [
    'check_duplicates' => true,
    'check_missing_controllers' => true,
    'check_missing_methods' => true,
],

'integrations' => [
    'telescope' => [
        'enabled' => class_exists(\Laravel\Telescope\TelescopeServiceProvider::class),
        'base_url' => '/telescope',
    ],
],
bash
php artisan route-visualizer:install
bash
php artisan vendor:publish --tag=route-visualizer-config
bash
php artisan vendor:publish --tag=route-visualizer-views
bash
php artisan vendor:publish --tag=route-visualizer-assets
bash
php artisan route-visualizer:install

GET /route-visualizer/routes?search=api&method=POST&middleware=auth&domain=api.example.com&namespace=App\Http\Controllers\Api&middleware_group=web&page=1&per_page=50
bash
php artisan vendor:publish --tag=route-visualizer-views