PHP code example of sbine / route-viewer

1. Go to this page and download the library: Download sbine/route-viewer 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/ */

    

sbine / route-viewer example snippets


public function tools()
{
    return [
        new \Sbine\RouteViewer\RouteViewer,
    ];
}

use Sbine\RouteViewer\RouteViewer;
use Sbine\RouteViewer\Column;

// Simple per-route resolver
RouteViewer::addColumn(
    Column::make('Domain', 'domain')
        ->using(fn (\Illuminate\Routing\Route $route) => $route->getDomain() ?? '—')
);

// Batch resolver (efficient for DB lookups, avoids N+1)
RouteViewer::addColumn(
    Column::make('Hits', 'hits')
        ->usingBatch(function (array $routes): array {
            $hits = DB::table('route_hits')
                ->whereIn('uri', array_column($routes, 'uri'))
                ->groupBy('uri')
                ->pluck(DB::raw('count(*)'), 'uri');

            return array_map(fn ($r) => $hits[$r['uri']] ?? 0, $routes);
        })
);

// Non-sortable column
RouteViewer::addColumn(
    Column::make('Notes', 'notes')
        ->using(fn ($route) => config("route-notes.{$route->uri}", ''))
        ->sortable(false)
);

php artisan vendor:publish --provider="Sbine\RouteViewer\ToolServiceProvider"