1. Go to this page and download the library: Download spatie/laravel-visit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / laravel-visit example snippets
return [
/*
* These classes are responsible for colorizing the output.
*/
'colorizers' => [
Spatie\Visit\Colorizers\JsonColorizer::class,
Spatie\Visit\Colorizers\HtmlColorizer::class,
],
/*
* These stats will be displayed in the response block.
*/
'stats' => [
...Spatie\Visit\Stats\DefaultStatsClasses::all(),
]
];
namespace Spatie\Visit\Stats;
use Illuminate\Contracts\Foundation\Application;
abstract class Stat
{
public function beforeRequest(Application $app)
{
}
public function afterRequest(Application $app)
{
}
abstract public function getStatResult(): StatResult;
}
namespace Spatie\Visit\Stats;
use Illuminate\Contracts\Foundation\Application;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
class RuntimeStat extends Stat
{
protected Stopwatch $stopwatch;
protected ?StopwatchEvent $stopwatchEvent = null;
public function __construct()
{
$this->stopwatch = new Stopwatch(true);
}
public function beforeRequest(Application $app)
{
$this->stopwatch->start('default');
}
public function afterRequest(Application $app)
{
$this->stopwatchEvent = $this->stopwatch->stop('default');
}
public function getStatResult(): StatResult
{
$duration = $this->stopwatchEvent->getDuration();
return StatResult::make('Duration')
->value($duration . 'ms');
}
}