扩展Laravel HTTP立面

发布于 2025-02-08 04:32:24 字数 198 浏览 1 评论 0原文

我正在尝试找到适当的方法来扩展Laravel HTTP客户幕立面。我不想每次都想从请求的响应中得到一些东西。我想添加更多的帮助者来防止这种情况。另外,我无法直接扩展客户,因为我使用宏观的外墙来减轻我的生活。

    json_decode($this->getBody()->getContents())->id;

I'm trying to find the right way to extend the Laravel Http Client Facade. I don't want to do this every time when I want to get something from the response of my request. I would like to add some more helpers to prevent this. Also I can't directly extend the client, because I'm using the facade with a macro to ease my life.

    json_decode($this->getBody()->getContents())->id;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2025-02-15 04:32:24

这已经是内置于客户端

$response = Http::get('http://example.com/users/1');
$response->json()['id'];
$response->object()->id;

甚至:

Http::get('http://example.com/users/1')['id'];

This is already built into the client.

$response = Http::get('http://example.com/users/1');
$response->json()['id'];
$response->object()->id;

Or even:

Http::get('http://example.com/users/1')['id'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文