mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/compatibility/mongodb-laravel-integration
MIT License
6.99k stars 1.42k forks source link

orderBy doesn't work #2298

Open sathio opened 3 years ago

sathio commented 3 years ago

Description:

orderby doesn't work

Steps to reproduce

  1. $query = Model::where('blah', 'blah')->orderBy('age', 'desc');

Expected behaviour

should return a query

Actual behaviour

an exception is raised ErrorException Undefined array key "column"

Logs: Illuminate\Foundation\Bootstrap\HandleExceptions::handleError vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php:740

nevermind, looks like there was some issue on my code. I swear I've been testing it for a lot but it seems it was my fault

ifbaran commented 3 years ago

It's working, i think you need to check your name of columns. Then you should to add "->get()" end of query. If you don't add "->get()" it returns "Jenssegers\Mongodb\Eloquent\Builder".

apvvyas commented 3 years ago

But this does not work for yajra datatables with mongo db ....on adding order by it returns Trying to access array offset on value of type int on doing order by