Laravel 11.2.0で、
fluent()
<!-- Syntax highlighted by torchlight.dev -->use Illuminate\Support\Facades\Http; $response = Http::get('https://jsonplaceholder.typicode.com/posts')->fluent(); $response->get('0.title'); // sunt aut facere... $response->collect()->pluck('title'); // ["sunt aut facere...", "qui est esse ", ...]
Carbon
別のきちんとした機能は、JSONデータを特定のタイプに変換することです。文字列の日付をインスタンスに変換できるこの例を見てみましょう:
<!-- Syntax highlighted by torchlight.dev -->use Illuminate\Support\Facades\Http; $response = Http::get('https://api.chucknorris.io/jokes/random')->fluent(); $response->date('created_at'); $response->date('updated_at'); /* Illuminate\Support\Carbon @1578231741 {#261 ▼ // routes/web.php:9 date: 2020-01-05 13:42:21.455187 UTC (+00:00) } */
などの他の役立つタイプもサポートしています。私のお気に入りの1つは、特定のデータを取得するためにboolean
やenum
などのおなじみの方法を使用することです。
enum
only
#Learn moreexcept
以上がLaravelでHTTPクライアント応答を使用するためにFluentを使用するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。