Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shaonlimit's avatar

How to fetch data from api in laravel?

can anyone please tell me how to fetch data from api in laravel?

0 likes
6 replies
shariff's avatar

You need to use HttpClient to call external API from laravel. For more information you can check here https://laravel.com/docs/10.x/http-client or https://laravel.com/docs/10.x/http-client#making-requests

shariff's avatar

@shaonlimit May be you have internet issue. I can able to view the documentation https://laravel.com/docs/10.x/http-client.

I can provide some examples from the documentation. examples

use Illuminate\Support\Facades\Http;
 
$response = Http::get('http://example.com');

$response->body() : string;
$response->json($key = null, $default = null) : array|mixed;
$response->object() : object;
$response->collect($key = null) : Illuminate\Support\Collection;
$response->status() : int;
$response->successful() : bool;
$response->redirect(): bool;
$response->failed() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;
shaonlimit's avatar

@shariff no the laravel blade file is loading and loading where the data will be showed

shariff's avatar

Can you show some code? what issue you are facing?

Please or to participate in this conversation.