I am facing a really weird problem. The problem is shortly:
$x = some_object;
return response()->json($x) => {}
return response()->json(some_object) => {some_object}
This is all of the code(The code goes inside the else statement):
public function checkCalls(Request $req)
{
$active_call = VideoCall::where("receiver_id", (int) $req->input("user_id"));
if ($active_call->where("call_situation", "call")->exists()) {
$active_call = $active_call->first();
$caller_id = $active_call->caller_id;
$caller = User::where("id", $caller_id)->first();
$caller_name = $caller->name;
$caller_img = $caller->image;
return response()->json([
"friend" => $caller_id,
"caller_name" => $caller_name,
"caller_img" => $caller_img
]);
} else if ($active_call->where("call_situation", "yes")->exists()) {
return response()->json("gorusme yapıyor");
} else if ($active_call->where("call_situation", "decline")->exists()) {
$caller_id = $active_call->where("call_situation", "decline")->first()->caller_id;
return response()->json("arama red edildi", $caller_id);
} else {
return response()->json("arama yok");
//this code runs, I m changing here to get different returns
}
}
When I change inside the else brackets, this returns true
return response()->json(VideoCall::where("receiver_id", (int) $req->input("user_id"))->exists());
But this returns false:
return response()->json($active_call->exists());
$active_call returns an empty object for some reason.
The only explanation is that $active_call changes in if() parentheses but I can't find anything that can change it.
So why is this happening?
*Edit: Made the question clearer, added a shorter version of the problem.
*Edit 2: The code inside the else statement is running. I m changing that return statement to get different results