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

Sawgore's avatar

How to insert parameters into a MongoDB eloquent aggregation function?

I have the following code in my controller.

public function show(Request $request) {

       $data = Book::raw(function ($collection, Request $request) {

          return $collection->aggregate([
             [
                '$match' => [
                   'T.HD.HD02' => ['$eq' => $request->date]
                ],
             ],
          ]);
       });
  
    }

I am receiving parameters from my Blade file and I want to insert them into this function. The name T.HD.HD02 refers to a date entered by the user.

The variable Request $request doesn't even work inside the function.

How can I make it recognize the Request parameters?

0 likes
0 replies

Please or to participate in this conversation.