Skip to content

Commit 5067230

Browse files
committed
feat(docs): add Http Client Response macro example
- Introduce `Illuminate\Http\Client\Response` macro support in Laravel 12.43. - Provide example usage for the `movieFields` macro.
1 parent d03eac4 commit 5067230

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/others/macros.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Laravel Response 类,它实现了 Macroable 特征,这意味着可以使用
5656
`Illuminate\Http\RedirectResponse`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/RedirectResponse.php)
5757
- [`Illuminate\Http\Request`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Request.php)
5858
- [`Illuminate\Http\Response`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Response.php)
59+
- [`Illuminate\Http\Client\Response`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Client/Response.php)
5960
- [
6061
`Illuminate\Http\UploadedFile`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/UploadedFile.php)
6162
- [`Illuminate\Mail\Mailer`](https://github.com/laravel/framework/blob/master/src/Illuminate/Mail/Mailer.php)
@@ -355,6 +356,22 @@ Response::macro('api', function(string|array $data, null|string $message = null,
355356
})
356357
```
357358

359+
### `Http Client Response`
360+
361+
自 Laravel 12.43 版本起,`Illuminate\Http\Client\Response` 类支持宏,具体查看这个 [PR](https://github.com/laravel/framework/pull/58115)
362+
363+
```php
364+
use Illuminate\Http\Client\Response;
365+
366+
Response::macro(
367+
'movieFields',
368+
fn () => $this->collect()->only('title', 'year', 'runtime', 'director', 'plot')
369+
);
370+
371+
$response = Http::get(...);
372+
$response->movieFields();
373+
```
374+
358375
### `Validation`
359376

360377
注意 `Validator` 使用是 **`extend`** 方法来自定义宏,并不是 `micro` 方法。

0 commit comments

Comments
 (0)