untymage
1 week ago

orderByDesc not working in Postgres

Posted 1 week ago by untymage

These are working on mysql driver :

mysql:

return Post::query()
            ->where('title', 'LIKE', "%$term%")
            ->orderByDesc('votes')
            ->take(5)
            ->pluck('visits');

Result:

  #items: array:5 [
    0 => 2221907
    1 => 1468691
    2 => 724319
    3 => 577753
    4 => 456866
  ]

But when i switch to postgres driver the orderByDesc and iLIKE not working correctly like mysql:

postgres:

return Post::query()
            ->where('title', 'ILIKE', "%$term%")
            ->orderByDesc('votes')
            ->take(5)
            ->pluck('visits');

result:

  #items: array:5 [
    0 => null
    1 => null
    2 => null
    3 => null
    4 => null
  ]

Please sign in or create an account to participate in this conversation.