├── .circleci └── config.yml ├── .php_cs ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── database └── migrations │ └── 2019_10_13_210659_create_route_usage_table.php ├── resources └── views │ ├── helpers │ └── sorting_link.blade.php │ └── index.blade.php └── src ├── Authorize.php ├── Console └── Commands │ └── UsageRouteCommand.php ├── Http └── Controllers │ └── RouteUsageController.php ├── Listeners └── LogRouteUsage.php ├── RouteUsage.php ├── RouteUsageServiceProvider.php └── routes.php /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # PHP CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-php/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | # Specify the version you desire here 10 | - image: circleci/php:7.1-node-browsers 11 | - image: circleci/mysql:5.7 12 | 13 | environment: 14 | MYSQL_HOST: 127.0.0.1 15 | MYSQL_ALLOW_EMPTY_PASSWORD: true 16 | MYSQL_ROOT_PASSWORD: null 17 | MYSQL_USER: root 18 | MYSQL_DATABASE: test_route_usage 19 | 20 | steps: 21 | - checkout 22 | 23 | - run: 24 | name: Install libs 25 | command: | 26 | sudo apt update # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev 27 | sudo docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd 28 | sudo docker-php-ext-install zip bcmath pdo_mysql 29 | sudo apt-get install default-mysql-client 30 | 31 | # Download and cache dependencies 32 | - restore_cache: 33 | keys: 34 | # "composer.lock" can be used if it is committed to the repo 35 | - v1-dependencies-{{ checksum "composer.json" }} 36 | # fallback to using the latest cache if no exact match is found 37 | # - v1-dependencies- 38 | 39 | - run: composer install -n --prefer-dist 40 | 41 | - save_cache: 42 | key: v1-dependencies-{{ checksum "composer.json" }} 43 | paths: 44 | - ./vendor 45 | 46 | - run: mysql -uroot -e 'CREATE DATABASE test_route_usage;' 47 | 48 | # Run tests 49 | - run: ./vendor/bin/phpunit 50 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in(__DIR__) 5 | ; 6 | 7 | $config = PhpCsFixer\Config::create() 8 | ->setRules([ 9 | '@PSR2' => true, 10 | '@PhpCsFixer' => true, 11 | 'list_syntax' => ['syntax' => 'long'], 12 | 'multiline_whitespace_before_semicolons' => false, 13 | ]) 14 | ->setFinder($finder) 15 | ; 16 | 17 | return $config; 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `route-usage` will be documented in this file 4 | 5 | ## 0.4 6 | **07 Dec 2019** | [git diff 0.3..0.4](https://github.com/julienbourdeau/route-usage/compare/0.3..0.4) 7 | 8 | * Support other databases - PR [#5](https://github.com/julienbourdeau/route-usage/pull/5) 9 | 10 | Instead of a raw MySQL query, the package is now using Eloquent 11 | to save the route usage entries. This brings support to other databases, 12 | so tests are now running using SQLite. 13 | 14 | ## 0.3 15 | **29 Oct 2019** | [git diff 0.2..0.3](https://github.com/julienbourdeau/route-usage/compare/0.2..0.3) 16 | 17 | * Hide HTML page behind Gate - PR [#13](https://github.com/julienbourdeau/route-usage/pull/13) 18 | 19 | In your `AuthServicePrivder::boot`, define a gate: 20 | 21 | ```php 22 | Gate::define('viewRouteUsage', function ($user) { 23 | return $user->isSuperAdmin(); 24 | }); 25 | ``` 26 | 27 | ## 0.2 28 | **28 Oct 2019** | [git diff 0.1..0.2](https://github.com/julienbourdeau/route-usage/compare/0.1..0.2) 29 | 30 | * Ignore OPTIONS http calls - PR [#12](https://github.com/julienbourdeau/route-usage/pull/12) 31 | 32 | * Ignore routes based on their name or uri - PR [#6](https://github.com/julienbourdeau/route-usage/pull/6) 33 | 34 | * Add style for HTML view - PR [#8](https://github.com/julienbourdeau/route-usage/pull/8) 35 | 36 | ## 0.1 37 | 38 | - initial release 39 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Julien Bourdeau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Route Usage for Laravel 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/julienbourdeau/route-usage.svg?style=flat-square)](https://packagist.org/packages/julienbourdeau/route-usage) 4 | [![Build Status](https://img.shields.io/travis/julienbourdeau/route-usage/master.svg?style=flat-square)](https://travis-ci.org/julienbourdeau/route-usage) 5 | 6 | This package keeps track of all requests to know what controller method, and when it was called. The goal is not to build some sort of analytics but to find out if there are unused endpoints or controller method. 7 | 8 | After a few years, any projects have dead code and unused endpoint. Typically, you removed a link on your frontend, nothing ever links to that old `/special-page`. You want to remove it, but you're not sure. 9 | Have look at the `route_usage` table and figure out when this page was accessed for the last time. Last week? Better keep it for now. 3 years ago? REMOVE THE CODE! 🥳 10 | 11 | 12 | /route-usage screenshot 13 | 14 | php artisan usage:route screenshot 15 | 16 | ## Installation 17 | 18 | You can install the package via composer: 19 | 20 | ```bash 21 | composer require julienbourdeau/route-usage 22 | ``` 23 | 24 | Run migrations to create the new `route_usage` table. 25 | 26 | ```bash 27 | php artisan migrate 28 | ``` 29 | 30 | Publish configuration 31 | 32 | ```bash 33 | php artisan vendor:publish --provider="Julienbourdeau\RouteUsage\RouteUsageServiceProvider" 34 | ``` 35 | 36 | ## Usage 37 | 38 | To access the route usage, you can do it in your terminal with the command. 39 | 40 | ```bash 41 | php artisan usage:route 42 | ``` 43 | 44 | To access the HTML table, you'll first need to define who can access it. By default, 45 | it's available only on `local` environment. 46 | 47 | In your `AuthServiceProvide`, in the `boot` method, define who can access this page: 48 | 49 | ```php 50 | Gate::define('viewRouteUsage', function ($user) { 51 | return $user->isSuperAdmin(); 52 | }); 53 | ``` 54 | 55 | Then, head over to `yourapp.tld/route-usage`. 56 | 57 | ## Configuration 58 | 59 | ### excluding-regex 60 | 61 | Here you may specify regex to exclude routes from being logged. 62 | Typically, you want may want to exclude routes from packages or dev controllers. 63 | The value must be a valid regex or anything falsy. 64 | 65 | ## Notes 66 | 67 | * I only logs request with a 2xx or 3xx HTTP response. I don't think the rest makes sense. Your opinion is welcome! 68 | * 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 because but last access was a year ago, it gives a false sense of importance to this unused route. 69 | 70 | ## Road to 1.0 release 71 | 72 | **Less SQL queries** 73 | 74 | I'll like to reduce the number of SQL queries performed. Typically, if a route 75 | is called, we don't need to log usage for the next 5 minutes. I'm thinking we could 76 | use some cache or split the data: attributes in mysql but last used date in Redis. 77 | 78 | 💡 Feel free to open an issue to discuss your ideas. 79 | 80 | **More package to ignore** 81 | 82 | Today, we ignore routes from Nova or Debugbar because there is nothing you can 83 | do about these routes. I'd like to support more packages out of the box. 84 | 85 | 📦 What package would you like to see added? 86 | 87 | ## About 88 | 89 | ### Changelog 90 | 91 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 92 | 93 | ### Contributing 94 | 95 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 96 | 97 | ### Security 98 | 99 | If you discover any security related issues, please email julien@sigerr.org instead of using the issue tracker. 100 | 101 | ### Credits 102 | 103 | - [Julien Bourdeau](https://github.com/julienbourdeau) 104 | - [All Contributors](../../contributors) 105 | 106 | ### Laravel Package Boilerplate 107 | 108 | This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com). 109 | 110 | ## License 111 | 112 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 113 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "julienbourdeau/route-usage", 3 | "description": "Log what routes were used and when. Easily figure out if one hasn't been called in a long time (and delete it! 🥳)", 4 | "keywords": [ 5 | "julienbourdeau", 6 | "route-usage" 7 | ], 8 | "homepage": "https://github.com/julienbourdeau/route-usage", 9 | "license": "MIT", 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Julien Bourdeau", 14 | "email": "julien@sigerr.org", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": ">= 7.1", 20 | "laravel/framework": ">= 5.8" 21 | }, 22 | "require-dev": { 23 | "orchestra/testbench": "3.8.*", 24 | "phpunit/phpunit": "^7.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Julienbourdeau\\RouteUsage\\": "src" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Julienbourdeau\\RouteUsage\\Tests\\": "tests" 34 | } 35 | }, 36 | "scripts": { 37 | "test": "vendor/bin/phpunit", 38 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 39 | 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "Julienbourdeau\\RouteUsage\\RouteUsageServiceProvider" 48 | ], 49 | "aliases": { 50 | "RouteUsage": "Julienbourdeau\\RouteUsage\\RouteUsageFacade" 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'name' => '/^(route-usage|nova|debugbar|horizon|telescope|telescope-api|__clockwork)\./', 18 | 'uri' => '/^nova/', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Specify date format 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the time format used to save the route usage 27 | | on the database. 28 | | 29 | | The value must be a valid time format. 30 | | 31 | */ 32 | 33 | 'date-format' => 'Y-m-d H:i:s', 34 | ]; 35 | -------------------------------------------------------------------------------- /database/migrations/2019_10_13_210659_create_route_usage_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 16 | $table->string('identifier', 40); 17 | $table->string('method', 12); 18 | $table->text('path'); 19 | $table->unsignedSmallInteger('status_code'); 20 | $table->text('action')->nullable(); 21 | $table->timestamps(); 22 | 23 | $table->unique('identifier'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('route_usage'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /resources/views/helpers/sorting_link.blade.php: -------------------------------------------------------------------------------- 1 | 5 | asc 6 | 7 | 8 | 12 | desc 13 | 14 | -------------------------------------------------------------------------------- /resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Route Usage 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Route Usage

15 |
16 | 17 | 18 | 21 | 22 | 23 | 26 | 29 | 30 | @forelse($routes as $route) 31 | 32 | 37 | 43 | 48 | 53 | 58 | 59 | @empty 60 | 61 | 62 | 63 | @endforelse 64 |
ID 19 |
@include('route-usage::helpers.sorting_link', ['orderByAttribute' => 'id'])
20 |
Route
 
Method
 
Code 24 |
@include('route-usage::helpers.sorting_link', ['orderByAttribute' => 'status_code'])
25 |
Last used 27 |
@include('route-usage::helpers.sorting_link', ['orderByAttribute' => 'updated_at'])
28 |
33 |
34 | {{ $route->id }} 35 |
36 |
38 |
39 | {{ $route->path }} 40 | {{ $route->action }} 41 |
42 |
44 |
45 | {{ $route->method }} 46 |
47 |
49 |
50 | {{ $route->status_code }} 51 |
52 |
54 |
55 | {{ $route->updated_at->diffForHumans() }} 56 |
57 |
No routes found.
65 |
66 |
67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/Authorize.php: -------------------------------------------------------------------------------- 1 | check($request) ? $next($request) : abort(403); 13 | } 14 | 15 | protected function check($request) 16 | { 17 | return App::environment('local') || 18 | Gate::check('viewRouteUsage', [$request->user()]); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Console/Commands/UsageRouteCommand.php: -------------------------------------------------------------------------------- 1 | false, 'uri' => false]; 21 | 22 | $routes = $this->splitRoutesByMethods(parent::getRoutes()) 23 | ->filter(function ($route) use ($regex) { 24 | if ( 25 | 'OPTIONS' == $route['method'] || 26 | $regex['name'] && preg_match($regex['name'], $route['name']) || 27 | $regex['uri'] && preg_match($regex['uri'], $route['uri']) 28 | ) { 29 | return false; 30 | } 31 | 32 | return true; 33 | }); 34 | 35 | // TODO: sort by updated_at and group by method+path 36 | $routeUsage = RouteUsage::all()->mapWithKeys(function ($r) { 37 | $key = $r->method.'.'.$r->path; 38 | 39 | return [$key => $r]; 40 | }); 41 | 42 | return $routes->map(function ($route) use ($routeUsage) { 43 | $usageKey = $route['method'].'.'.$route['uri']; 44 | $lastUsed = $routeUsage->has($usageKey) ? 45 | $routeUsage->get($usageKey)->updated_at->diffForHumans() 46 | : 'Never'; 47 | 48 | return $this->option('compact') ? 49 | [ 50 | 'method' => $route['method'], 51 | 'uri' => $route['uri'], 52 | 'last used' => $lastUsed, 53 | 'action' => $route['action'], 54 | ] : [ 55 | 'domain' => $route['domain'], 56 | 'method' => $route['method'], 57 | 'uri' => $route['uri'], 58 | 'last used' => $lastUsed, 59 | 'name' => $route['name'], 60 | 'action' => $route['action'], 61 | 'middleware' => $route['middleware'], 62 | ]; 63 | })->toArray(); 64 | } 65 | 66 | protected function splitRoutesByMethods(array $routes) 67 | { 68 | return collect($routes)->transform(function ($r) { 69 | $splitRoutes = []; 70 | foreach (explode('|', $r['method']) as $m) { 71 | $r['method'] = $m; 72 | $splitRoutes[] = $r; 73 | } 74 | 75 | return $splitRoutes; 76 | })->flatten(1)->reject(function ($r) { 77 | return 'HEAD' === $r['method']; 78 | })->values(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Http/Controllers/RouteUsageController.php: -------------------------------------------------------------------------------- 1 | get('orderBy', 'updated_at'); 14 | $sort = $request->get('sort', 'asc'); 15 | 16 | if (is_null($route = RouteUsage::first())) { 17 | return view('route-usage::index', ['routes' => []]); 18 | } 19 | 20 | $attributes = array_keys($route->getAttributes()); 21 | if (!in_array($order, $attributes)) { 22 | $order = 'updated_at'; 23 | } 24 | if (!in_array($sort, ['asc', 'desc'])) { 25 | $sort = 'asc'; 26 | } 27 | 28 | return view('route-usage::index', [ 29 | 'routes' => RouteUsage::orderBy($order, $sort)->get(), 30 | ]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Listeners/LogRouteUsage.php: -------------------------------------------------------------------------------- 1 | shouldLogUsage($event)) { 12 | return; 13 | } 14 | 15 | extract($this->extractAttributes($event)); 16 | 17 | RouteUsage::updateOrCreate([ 18 | 'identifier' => $identifier, 19 | ], [ 20 | 'method' => $method, 21 | 'path' => $path, 22 | 'status_code' => $status_code, 23 | 'action' => $action, 24 | 'updated_at' => $date, 25 | ]); 26 | } 27 | 28 | protected function shouldLogUsage($event) 29 | { 30 | if ($event->request->isMethod('options')) { 31 | return false; 32 | } 33 | 34 | $status_code = $event->response->getStatusCode(); 35 | if ($status_code >= 400 || $status_code < 200) { 36 | return false; 37 | } 38 | 39 | $route = $event->request->route(); 40 | $regex = config('route-usage.excluding-regex'); 41 | 42 | // $route is not set when using Dingo router 43 | // See https://github.com/julienbourdeau/route-usage/issues/22 44 | if (is_null($route)) { 45 | return true; 46 | } 47 | 48 | if (isset($regex['name']) && $regex['name'] && preg_match($regex['name'], $route->getName())) { 49 | return false; 50 | } 51 | 52 | if (isset($regex['uri']) && $regex['uri'] && preg_match($regex['uri'], $route->uri)) { 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | protected function extractAttributes($event) 60 | { 61 | $path = ($route = $event->request->route()) ? $route->uri : $event->request->getPathInfo(); 62 | $action = $route ? $route->getAction()['uses'] : null; 63 | 64 | if ($action instanceof \Closure) { 65 | $action = '[Closure]'; 66 | } elseif (!is_string($action) && !is_null($action)) { 67 | $action = '[Unsupported]'; 68 | } 69 | 70 | return [ 71 | 'status_code' => $status_code = $event->response->getStatusCode(), 72 | 'method' => $method = $event->request->getMethod(), 73 | 'path' => $path, 74 | 'action' => $action, 75 | 'identifier' => sha1($method.$path.$action.$status_code), 76 | 'date' => date(config('route-usage.date-format', 'Y-m-d H:i:s')), 77 | ]; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/RouteUsage.php: -------------------------------------------------------------------------------- 1 | 'datetime', 15 | 'updated_at' => 'datetime', 16 | ]; 17 | 18 | public function getDateFormat() 19 | { 20 | return config('route-usage.date-format', 'Y-m-d H:i:s'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/RouteUsageServiceProvider.php: -------------------------------------------------------------------------------- 1 | listen(); 20 | 21 | $this->gate(); 22 | 23 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'route-usage'); 24 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 25 | $this->loadRoutesFrom(__DIR__.'/routes.php'); 26 | 27 | if ($this->app->runningInConsole()) { 28 | $this->publishes([ 29 | __DIR__.'/../config/config.php' => config_path('route-usage.php'), 30 | ], 'config'); 31 | 32 | $this->commands([ 33 | UsageRouteCommand::class, 34 | ]); 35 | } 36 | } 37 | 38 | protected function gate() 39 | { 40 | Gate::define('viewRouteUsage', function ($user) { 41 | return false; 42 | }); 43 | } 44 | 45 | protected function listen() 46 | { 47 | Event::listen(RequestHandled::class, LogRouteUsage::class); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/routes.php: -------------------------------------------------------------------------------- 1 | middleware(['web', \Julienbourdeau\RouteUsage\Authorize::class]) 7 | ->name('route-usage.index'); 8 | --------------------------------------------------------------------------------