diff --git a/http-client.md b/http-client.md index ba3a8b50a3..53dc9b0811 100644 --- a/http-client.md +++ b/http-client.md @@ -621,6 +621,23 @@ $batch->finished(); // Indicates if the batch has request failures... $batch->hasFailures(); ``` + +#### Deferring Batches + +When the `defer` method is invoked, the batch of requests is not executed immediately. Instead, Laravel will execute the batch after the current application request's HTTP response has been sent to the user, keeping your application feeling fast and responsive: + +```php +use Illuminate\Http\Client\Batch; +use Illuminate\Support\Facades\Http; + +$responses = Http::batch(fn (Batch $batch) => [ + $batch->get('http://localhost/first'), + $batch->get('http://localhost/second'), + $batch->get('http://localhost/third'), +])->then(function (Batch $batch, array $results) { + // All requests completed successfully... +})->defer(); +``` ## Macros