Skip to content

Variable in a Collection request #2538

@zane-shus

Description

@zane-shus

This is not a feature request of a bug. My a lack of skill issue.

I have a laravel API app, and its meant to take a GET ID and use that in a match to get the individual item from Mongo. All my static queries are working ok.

My code is:

 $value = (int)$sub_responseItem['value'];
 $page = Track::raw(function ($collection) {
      return $collection->aggregate(
       [['$match' => ['my_id' => $value ]]]
                                            );
                                        });
    $response = new MyCollection($page);

My error is:

message": "Undefined variable $value",
    "exception": "ErrorException",
    "file": "/var/www/html/app/Http/Controllers/api/v1/MyController.php",
    "line": 79,  (this is the line with $value on it)

If I change this [['$match' => ['my_id' => $value ]]] to this [['$match' => ['my_id' => 1 ]]], it works ok.

And if i do a var_dump($value); I get (int)1

Can anyone see what I am doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions