Skip to content

Instantly share code, notes, and snippets.

@thinkstylestudio
Last active June 12, 2024 18:51
Show Gist options
  • Save thinkstylestudio/47fa8d52f1c8b34cd14d6d6e8db500f4 to your computer and use it in GitHub Desktop.
Save thinkstylestudio/47fa8d52f1c8b34cd14d6d6e8db500f4 to your computer and use it in GitHub Desktop.
php artisan route:list --path=api --json | jq -r '.[] | select(.name != null) | .name'
<?php
$dir = 'tests/Feature';
$files = scandir($dir);
$routeNames = [];
foreach ($files as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$filePath = $dir . '/' . $file;
$fileContent = file_get_contents($filePath);
preg_match_all("/route\('([^']*)'\)/", $fileContent, $matches);
foreach ($matches[1] as $match) {
$routeNames[$match] = true;
}
}
$routeNames = array_keys($routeNames);
print_r($routeNames);
<?php
$apiFileContent = file_get_contents('routes/api.php');
$httpVerbs = ['get', 'post', 'put', 'patch', 'delete', 'options'];
$routeCounts = array_fill_keys($httpVerbs, 0);
$routePaths = array_fill_keys($httpVerbs, []);
foreach ($httpVerbs as $verb) {
preg_match_all("/Route::{$verb}\('([^']*)'/", $apiFileContent, $matches);
$routeCounts[$verb] = count($matches[0]);
$routePaths[$verb] = $matches[1];
}
print_r($routeCounts);
print_r($routePaths);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment