Dono's avatar
Level 1

Routing and PHP7 types

Hello,

I have a controller with the following parameter using PHP7 type:

class UsersController extends Controller
{
        public function show(int... $ids)
        {
            return User::whereIn('id', $ids)->get();
        }
}

And a route like that

$group->get('users/{id}', 'UsersController@show');

When I call my Api with one id everything is ok but when I try with multiple parameters (ex. /users/1,2,3) I got an error: "A non well formed numeric value encountered"

Is it possible to use PHP7 types with Lumen? I would like to avoid using a string and explode it to retrieve my ids.

Thanks a lot!

0 likes
1 reply
bobbybouwmann's avatar

That parameter you give to the function is not a valid integer so it will never work like that.. You either need to explode the string or pass them in another way to your controller.

Right now PHP is retrieving the value 1,2,3 in the show method, this is not an integer and therefore you get an error.

Please or to participate in this conversation.