1

I'm using Laravel-MongoDB from jenssegers. Now I wish to create a custom query. By documentation, I need to use the RAW method.

$model = User::whereRaw(['$limit : 5'])->get();
dd($model);

Why my result is empty?

Collection {#235 ▼
  #items: []
}
Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
lolalola
  • 3,773
  • 20
  • 60
  • 96

1 Answers1

0

The docs for Moloquent's whereRaw method expect a complete PHP array instead of passing a string of JSON object inside a PHP array.

$model = User::whereRaw(['$limit' => '5'])->get();

Give it a try, and let me know if it helps.

Update

The docs also list that the following is possible:

$model = User::take(5)->get();
Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148