Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Laravel Spy

Laravel Spy stats

Downloads
79
Stars
19
Open Issues
0
Forks
1

View on GitHub →

A Laravel package to track outgoing HTTP requests.

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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Farayaz Laravel Spy Related Articles

HTTP Client Request Attributes in Laravel 12.42 image

HTTP Client Request Attributes in Laravel 12.42

Read article
Log Outgoing HTTP Requests with the Laravel Spy Package image

Log Outgoing HTTP Requests with the Laravel Spy Package

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
Conduct better email testing with Mail Intercept image

Conduct better email testing with Mail Intercept

Read article
Laravel 5.7.10 Released image

Laravel 5.7.10 Released

Read article
Statamic 2.9 is now released image

Statamic 2.9 is now released

Read article
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
PhpStorm logo

PhpStorm

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

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu