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

Naxionman's avatar

Query fetches only 2 records

Hello everyone, This is my first post here, so I kindly ask you to be a liitle lenient to me.

I have set a Laravel API for a game I am building in Unity and evrything works fine, except for one thing. When I call the following function in my API I expect to get the details of some test users, but it seems I'm only getting the first two of the array I send. I guess ther is something wrong with my function.

        $fff = \DB::table('users')->select('username','levels_unlocked', 'souvenirs','experience','country')
            ->whereIn('fbId', $request)
            ->orderBy('levels_unlocked', 'DESC')
            ->orderBy('souvenirs', 'DESC')
            ->orderBy('experience', 'DESC')
            ->get();

        $friends = [
            'message' => 'Successfully got the friends',
            'Friend Details' => $fff,
        ];

        return response()->json($friends, 200);
    }

The POST data I am sending is this array:

	
	{
		"id": "109018004086476",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "108789067444943",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "106229827701237",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "103444594649848",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "101945741471074",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "116821086632522",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "115870070061766",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	},
	{
		"id": "101866724812388",
		"picture": {
			"data": {
				"height": 50,
				"is_silhouette": true,
				"url": "https:\/\/scontent.fath3-3.fna.fbcdn.net\/v\/t31.0-1\/cp0\/c15.0.50.50a\/p50x50\/10733713_10150004552801937_4553731092814901385_o.jpg?_nc_cat=1&_nc_sid=12b3be&_nc_ohc=drm1lEUx5A4AX-56ECf&_nc_ht=scontent.fath3-3.fna&oh=984d3a8b4ff8e940890df4f198962cef&oe=5EAAEFAC",
				"width": 50
			}
		}
	}
]

I have testing this in Insomnia moving the nodes around, and what I get is just the first and the second fff (Facebook Flarrot Friend)

Thanks for reading this and thanks in advance for any suggestions!

0 likes
7 replies
Ashraam's avatar
Ashraam
Best Answer
Level 41

I don't see any particular problem here..

if you dd($fff) you only have 2 rows ? Then it comes from the data in the DB :/

Anyway you should use Eloquent model instead of DB class, more readable and easiest to use if you have relationship etc

Naxionman's avatar

Thanks for the reply Ashraam! Indeed, I get only 2. I tried to remove everything but the "id" nodes from the POST JSONObject I send, and I realized that the results are as expected. Could it be that POST data has a limit?

teos_97's avatar

Hey could you dd the request object? Thx

teos_97's avatar

Try selecting ‘fbId’ column as well, and probably do a where(‘fbId’, $request->id)

Naxionman's avatar

The problem was likely the size of the POST data I was sending. I asked this question because I thought that the query was problematic. Since I realized there was nothing worng with it I removed the unneccecary nodes from the JSONObject I was sending and the problem was solved. Thank you from your answers. I chose Ashraam's answer as the best one because that was really the answer that helped me sort out the problem.

1 like

Please or to participate in this conversation.