Combining with Macros

  • Laravel's HTTP client components support macros
  • Middleware macros are applied to Illuminate\Http\Client\PendingRequest, not the Http facade
  • Closures can be passed as macro arguments for additional control
  • This lets you define reusable, middleware-equipped HTTP clients across your application
$response = Http::app()
    ->withErrorHandling(function ($response, $body) {
        return data_get($errors, 'input.name', null) ===
            'The name is invalid';
    })
    ->mutation('CreateAction', [...]);

← / → navigate · N notes · Esc exit