This package keeps track of all requests in order to know what controller method was used. The goal is to find out if there are unused endpoints or controller methods in your app. This is not to build any sort of analytics!
After a few years, any projects have dead code and unused endpoints. Typically, you removed a link
on your frontend, nothing ever links to that old /special-page
. You might want to remove it, but
you're not sure.
With this package, you can have look at the route_usage
table and figure out when this page was accessed
for the last time.
When was this page used for the last time? Last week? Better keep it for now. 3 years ago? REMOVE THE CODE! 🥳
Notes
- This package only logs request with a 2xx or 3xx HTTP response. I don't think the rest make sense but if you think it does, please reach out.
- In the very first version, I was incrementing a
count
attribute. I removed it because I think it gives a wrong information. If it was used a lot but wasn't accessed for over a year, it might give a false sense of importance to this unused route.
Installation
Install the package via composer.
__torchlight-block-[e5ccd0e8-0751-4aee-8a98-4df220f04bc6]__
Run migrations to create the new route_usage
table.
__torchlight-block-[a75a73e6-2247-4f47-bcba-2f36e7c44a19]__
Optionally, publish the configuration if you need to modify it.
__torchlight-block-[929296dc-7dd4-452c-82c8-b3d7f97d95c9]__
Usage
Command line
To access the route usage, you can do it in your terminal with the command.
__torchlight-block-[7626e467-000c-4b47-af98-f1e5d7667414]__
HTML table
To access the HTML table, you'll first need to define who can access it. By default,
it's available only on local
environment.
In your AuthServiceProvide
, in the boot
method, specify who can access this page with a gate.
__torchlight-block-[f41c4f6a-4bf7-47c6-aa3a-0ce3a37a9d26]__
Then, head over to yourapp.tld/route-usage
.
Configuration
excluding-regex
Here you may specify regex to exclude routes from being logged. Typically, you want may want to exclude routes from packages or dev controllers. The value must be a valid regex or anything falsy.
Road to 1.0 release
Less SQL queries
I'd like to reduce the number of SQL queries performed. Typically, if a route is called, we don't need to log usage for the next 5 minutes. I'm thinking we could use some cache or split the data: attributes in mysql but last used date in Redis.
💡 Feel free to open an issue to discuss your ideas.
More package to ignore
Today, we ignore routes from Nova or Debugbar because there is nothing you can do about these routes. I'd like to support more packages out of the box.
📦 What package would you like to see added?
Changelog
v0.4
07 Dec 2019 | git diff 0.3..0.4
Support other databases - PR #5
Instead of a raw MySQL query, the package is now using Eloquent to save the route usage entries. This brings support to other databases, so tests are now running using SQLite.
v0.3
29 Oct 2019 | git diff 0.2..0.3
Hide HTML page behind Gate - PR #13
In your
AuthServicePrivder::boot
, define a gate:__torchlight-block-[800ecb74-011a-49d0-9cdf-244dc70f8dff]__
v0.2
28 Oct 2019 | git diff 0.1..0.2
Ignore OPTIONS http calls - PR #12
Ignore routes based on their name or uri - PR #6
Add style for HTML view - PR #8
v0.1
- Initial release