<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ohseesoftware / laravel-server-analytics example snippets
// Kernel.php
protected $middleware = [
// ... other middlware here
\OhSeeSoftware\LaravelServerAnalytics\Http\Middleware\LogRequest::class,
];
$userId = $request->user()?->id ?? null
// AppServiceProvider
use OhSeeSoftware\LaravelServerAnalytics\Facades\ServerAnalytics;
public function boot()
{
// Do not track `/home` or `/admin/*` routes
ServerAnalytics::addRouteExclusions([
'/home',
'/admin/*'
]);
}
// AppServiceProvider
use OhSeeSoftware\LaravelServerAnalytics\Facades\ServerAnalytics;
public function boot()
{
// Do not track `POST` or `PUT` requests
ServerAnalytics::addMethodExclusions(['POST', 'PUT']);
}
// CustomRequestDetails.php
use OhSeeSoftware\LaravelServerAnalytics\RequestDetails;
class CustomRequestDetails extends RequestDetails
{
public function getMethod(): string
{
// Set the stored `method` as "TEST" for all requests
return 'TEST';
}
}
use OhSeeSoftware\LaravelServerAnalytics\Repositories\AnalyticsRepository;
public function loadAnalytics(AnalyticsRepository $analytics)
{
$records = $analytics->query()->where('method', 'GET')->get();
}
use OhSeeSoftware\LaravelServerAnalytics\Models\Analytics;
$analytics = Analytics::relatedTo($user);
use OhSeeSoftware\LaravelServerAnalytics\Models\Analytics;
$analytics = Analytics::hasMeta('foo');
use OhSeeSoftware\LaravelServerAnalytics\Models\Analytics;
$analytics = Analytics::withMetaValue('foo', 'bar');