In this tutorial im going to share how to print api data in blade page follow this tutorial i have mentioned in very easy way.
Php artisan make:controller PostController
Next put below code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class PostController extends Controller
{
public function getallpost()
{
$response = Http::get('https://jsonplaceholder.typicode.com/posts');
return view('allpost',['data'=>$response->json()]);
}
}
Go to route/Api.php and paste below code
Route::get('/getdata','PostController@getallpost');
Route::get('/singledata/{id}','PostController@getPostById');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
@foreach ($data as $item)
<h2>{{$item['title']}}</h2>
@endforeach
</body>
</html>
Output:-