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

maltekiefer's avatar

Passed a var to second query

Hi,

I have a query like this:

    public function getInstalledHostsSoftwareProduct($id)
    {
        $data = Host::whereNull('deleted_at')->whereHas('softwarelicense', function ($query, $id) {return $query->where('softwareproduct_id', '=', $id);})->with('hosttype')->with('manufacturer')->with('office.site')->with('enduser')->get();
        return response()->json($data);
    }

But when I make it like this, I get this error:

ArgumentCountError
Too few arguments to function

This is my route:

Route::get('/getInstalledHostsSoftwareProduct/{id}', 'HostsController@getInstalledHostsSoftwareProduct')->where('id', '[0-9]+');

What is my mistake here?

0 likes
1 reply
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

You are passing id in the wrong way

$data = Host::whereNull('deleted_at')->whereHas('softwarelicense', function ($query) use ($id) {
return $query->where('softwareproduct_id', '=', $id);
}
1 like

Please or to participate in this conversation.