Example blog

Log route statistics for users and teams

[ad_1]

Laravel Route Statistics is a package from @bilfeldt for recording statistics on the use of routes by users and teams in a Laravel application. This package allows you:

  • See how much each user is using the app and what part of the app they are using
  • Check if unauthenticated users are making a lot of requests to your app

Using Laravel’s middleware, the package allows you to enable route logging globally, or you can enable it for route groups and individual routes through middleware:

1Route::middleware(['routestatistics'])

2 ->get('/example', /* ... */);

Finally, you can even enable logging via a query macro:

1public function index(Request $request)

2{

3 $request->routeStatistics();

4 // ...

5 return view('example');

6}

This package logs queries to the database with the following fields by default:

  • user_id – the identifier if authenticated
  • team_id – the team identifier associated with the request (if available)
  • method – the HTTP method
  • route – the name of the route (if available) or the URI of the route
  • status – the HTTP status code
  • ip – the IP of the request
  • date – the date of the request stored as datetime

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

[ad_2]
Source link