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

makapaka's avatar

Is a get request with array of numbers valid

I'm just wanting to sent a bunch of ids in a get request and im not sure if its really valid - the request could be 20 or 50 ids so I don't think its ideal to have them all as query params?

If its valid, I am also getting a weird problem when i do $request-all() with an empty request body, when I then do count($request-all()) its always returning 1 , event if request is totally empty ?

The request body i'm trying in Postman test is simply [1, 2, 3, 4, 5] thanks

0 likes
7 replies
Snapey's avatar

it's not an array, it's just a string which is why you only get one parameter from count

1 like
makapaka's avatar

@Snapey thank you - whats the proper way to send the array in the request body so it's recognised as array?

jlrdw's avatar

You can send comma separated then use split on the back end.

2 likes
CodeCanyon's avatar

You can try this as a query parameter to GET request.

Passing a serialize array.

Your route will be like this:

Route::get('/sample_route/{ids}', 'TestController@index');

In browser/api tool you need to pass a serialize array.

$array = [1,5,7,8]; $ser_arr = serialize($array);

/sample_route/$ser_arr

In the controller get the values like this and test.

class TestController extends Controller
{
    public function index($ids)
    {
        $unser_arr = unserialize($ids);
        dd(print_r($unser_arr));
    }
}
CodeCanyon's avatar

@automica

can also.

I just used the typical Laravel debug way.

debug and die - dd()

but just dump() won't stop the execution of the code.

in that case need to use:

dump($unser_arr) die();

Snapey's avatar

@CodeCanyon

I just used the typical Laravel debug way.

no you didn't - you stuck print_r in there for some reason

Using print_r is not advised because it can get itself into a recursion loop

Please or to participate in this conversation.