Have you tried anything like:
return response()->json(['something'=>$data]);
Just to make sure you are not using some reserved key?
Also what do you have at frontend?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hi developers . it's my first time with rest api ,using laravel as a backend .
so the probleme is that i can't achieve to return my data ($users) for exemple.,it returns this message in
browser console "this request has no response data available".
so first this is my route in routes/api.php :
Route::middleware('jwt.auth')->get('users', function () {
return auth('api')->user();
});
Route::post('/testlogin', 'Api\TestController@login'); //this is my route
for my controller app/http/controllers/Api/TestController :
public function login()
{
try {
$postdata = json_decode(file_get_contents("php://input"), true);
$credentials['email'] = $postdata['email'];
$credentials['password'] = $postdata['password'];
if (!$token = auth('api')->attempt($credentials)) {
return response()->json(['error' => 'Unauthorized'], 401);
}
$data=array();
$data['token']=$token;
$data['expires']=auth('api')->factory()->getTTL() * 60;
//when i return response()->json($data['token']); it show's the the token but when i return response()->json(['data'=>$data]); no response at all.
return response()->json($data);
} catch (Exception $e) {
return response()->json("error");
}
}
Please or to participate in this conversation.