I create two laravel projects. One is for backend connect with database and second project is for frontend. And then i create route API from projectone (backend project) get data from database and pass to json. and i want projecttwo(frontend) get the data from api url.
i try this code:
My API route in first project:
Route::get('test',function(){
$response=DB::table('student_tbl')->select('title')->get();
return response()->json($response,200);
});
My Secondproject:
$client = new \GuzzleHttp\Client();
// Create a request
$request = $client->get('http://localhost/myfirstproject/public/api/test');
// Get the actual response without headers
$response = $request->getBody();
$json_decode=json_decode($response,true);
foreach ($json_decode as $key => $value) {
echo $value['title'].'<br>';
}
Buti get 500 internal server error.
How to fixed this?