Index

Laravel Nightwatch: Log outgoing requests from Saloon

Published

Tags

#laravel #nightwatch #saloon

Laravel Nightwatch has been released this morning, and on Unolia, we are using Saloon to make outgoing HTTP requests to our API. I wanted to log these requests in Nightwatch so I can see them in the dashboard.


UPDATE 21 June 2025: I pushed a PR to Saloon to add support for Laravel Nightwatch, which is available in Saloon v3.6.0 and later. Just use the following command and skip this article:

Copied!
composer require saloonphp/laravel-plugin "^3.6.0"

To log outgoing requests from Saloon in Laravel Nightwatch, you'll need to create a custom HTTP sender that integrates Nightwatch's middleware.

Following the Saloon and Nightwatch documentation, create this new class wherever you need it, for example, in app/Http/HttpSender/LaravelSender.php:

Copied!
<?php
 
namespace App\Http\HttpSender;
 
use Laravel\Nightwatch\Facades\Nightwatch;
use Saloon\HttpSender\HttpSender;
 
class LaravelSender extends HttpSender
{
public function __construct()
{
parent::__construct();
 
$this->handlerStack->push(
Nightwatch::guzzleMiddleware()
);
}
}

And edit your config/saloon.php config file and change this line:

Copied!
'default_sender' => \App\Http\HttpSender\LaravelSender::class,

Simple!

This extends the Laravel Saloon HTTP sender to include the Laravel Nightwatch middleware.

Now, whenever you make an outgoing request using Saloon, it will be logged in Laravel Nightwatch.

Syntax highlighting provided by torchlight.dev.

Discussion on Bluesky

likes
reposts
comments

Comments

Reply on Bluesky to join the conversation.