我目前正在使用Laravel的WordPress。我在WordPress中发帖并使用WordPress REST API和GuzzleHttp在我的Laravel应用程序中显示帖子。有没有什么办法可以使用不同的过滤器,比如where(),sortBy()等来过滤使用GuzzleHttp从WordPress REST API接收的数据?
是的,您可以将json响应序列化为Laravel Collection并从那里使用functions like that。
$response = $response->getBody();
true
以始终输出数组。
$responseArray - json_decode($response, true);
$collection = collect($responseArray);
简而言之:
$collection = collect( json_decode( $response->getBody(), true ) );
$sortedByPrice = $collection->sortBy('price');