Package

Farayaz Laravel Spy

A Laravel package to track outgoing HTTP requests.

Package

farayaz/laravel-spy

View on GitHub →

Laravel Spy

Laravel Spy is a lightweight Laravel package designed to track and log outgoing HTTP requests made by your Laravel application.

This package is useful for debugging, monitoring, and auditing external API calls or HTTP requests, providing developers with a zero config, simple way to inspect request details such as URLs, methods, headers, and responses.

Features

  • Tracks all outgoing HTTP requests made via Laravel's HTTP client.
  • Logs request details, including URL, method, headers, payload, and response.
  • Configurable logging options to customize and obfuscate sensitive data.

Requirements

  • PHP: ^8.1
  • Laravel: ^10.0 | ^11.0 | ^12.0
  • Development Dependencies (optional):
    • laravel/pint: ^1.0 (for code style linting)
    • phpunit/phpunit: ^9.0 (for running tests)

Installation

You can install the package via Composer:

composer require farayaz/laravel-spy

The package uses Laravel's auto-discovery feature. After installation, the package is ready to use with its default configuration.

By Default Laravel-Spy logs all HTTP requests and API calls. You can customize it to exclude specific URLs or obfuscate sensitive data.

Configuration

To customize the behavior of Laravel Spy, you can publish the configuration file:

php artisan vendor:publish --provider="Farayaz\LaravelSpy\LaravelSpyServiceProvider"
php artisan migrate

This will create a config/spy.php file where you can configure the following options:

'table_name' => 'http_logs',
 
'enabled' => env('SPY_ENABLED', true),
'db_connection' => env('SPY_DB_CONNECTION'),
 
'exclude_urls' => explode(',', env('SPY_EXCLUDE_URLS', '')),
'obfuscates' => explode(',', env('SPY_OBFUSCATES', 'password')),

Usage

Once installed and configured, Laravel Spy automatically tracks all outgoing HTTP requests made using Laravel's Http facade or HTTP client. The package logs the following details for each request:

  • The full URL of the request
  • The HTTP method (e.g., GET, POST, PUT)
  • Request Headers
  • Request Body
  • Response Header
  • Response Body
  • Response HTTP Status code

Example:

Once you’ve installed Laravel-Spy via Composer and published the configuration, open your web.php file and add the following line to start logging results into the http_logs table in your database:

Route::get("/spy", function () {
Http::get('https://github.com/farayaz/laravel-spy/');
});

Now head to the http_logs table to view the logged parameters.

Cleaning up logs

Laravel Spy provides a spy:clean command to remove old HTTP logs:

# Clean logs based on your config
php artisan spy:clean
 
# Clean logs older than 30 days
php artisan spy:clean --days=30
 
# Clean logs matching URL pattern
php artisan spy:clean --days=1 --url=api/users

Automated cleanup

You can schedule automatic cleanup in your Laravel scheduler:

// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('spy:clean')->daily();
}

Contributing

Contributions are welcome! To contribute to Laravel Spy:

  • Fork the repository on GitHub.
  • Clone your fork and create a new branch (git checkout -b feat-your-feature).
  • Run code style checks with Laravel Pint (vendor/bin/pint).
  • Commit your changes and push to your fork.
  • Create a pull request with a clear description of your changes.

Issues

If you encounter any issues or have feature requests, please open an issue on the GitHub repository. Provide as much detail as possible, including:

  • Laravel version
  • PHP version
  • Package version
  • Steps to reproduce
  • Expected vs. actual behavior
  • Any relevant error messages or logs

License

Laravel Spy is open-sourced software licensed under the MIT License.

Contact

For questions or support, reach out via the GitHub repository or open an issue.

Farayaz Laravel Spy Related Articles

Log Outgoing HTTP Requests with the Laravel Spy Package image

Log Outgoing HTTP Requests with the Laravel Spy Package

Read article
HTTP Client Request Attributes in Laravel 12.42 image

HTTP Client Request Attributes in Laravel 12.42

Read article
Laravel SpaceOCR: Parse Images and Multi-page PDFs in Laravel image

Laravel SpaceOCR: Parse Images and Multi-page PDFs in Laravel

Read article
Laravel 5.7.10 Released image

Laravel 5.7.10 Released

Read article
Mock PHP Classes in Tests With the Double Library image

Mock PHP Classes in Tests With the Double Library

Read article
Conduct better email testing with Mail Intercept image

Conduct better email testing with Mail Intercept

Read article

Pushsilver

Pushsilver is simple invoicing for freelancers and small studios — send polished invoices, automate reminders, and get paid on time without the bloat.

Pushsilver

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum