logo

Diffing Laravel routes after a major upgrade

No one likes a broken link

Joel Clermont
Joel Clermont
2025-09-23

We recently did a pretty big internal overhaul of the Mastering Laravel site. Among the other changes, we restructured a bunch of routes.

With a public-facing, content-heavy site like ours, this makes me a bit cautious. I wanted to be sure we didn't inadvertently break any external sites linking to us.

First, I dumped the full route table from the old site, and then repeated this for the new site. To give me a cleaner diff, I exported as JSON instead of the tabular format:

php artisan route:list --json > ../routes-old.json
php artisan route:list --json > ../routes-new.json

Laravel lets you specify a sort option, but you can only sort by one field. To get a more precise sort, I used jq to normalize the sort order:

jq 'map({
  method: .method,
  uri: .uri,
  name: .name,
  action: .action,
  middleware: (.middleware|sort)
}) | sort_by(.uri, .method, .name)' ../routes-old.json > ../routes-old.sorted.json

# repeat for the ../routes-new.json file

With these two normalized JSON files, I can then run a diff for these two files.

A visual diff made it very apparent what exactly had changed, giving me the confidence we wouldn't break links after launch.

Here to help,

Joel

P.S. Need some advice on a big refactor or project you're working on? An expert review can save you a lot of trouble. Book a quick call.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.