Level 30
Try
DB::table('subjects')->orderBy('name', 'desc')->get()
or
Subject::orderBy('name','desc')->get()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to run a query with orderBy using DB::table('subjects')->orderBy('name', 'desc') but it throws an error Undefined property: Illuminate\Database\MySqlConnection::$id.
If I do query like this Subject::all() or any of these - it works fine.
I tried with use DB or use Illuminate\Support\Facades\DB but none of them work.
My model is Subject and table is called subjects
What am I doing wrong?
Try
DB::table('subjects')->orderBy('name', 'desc')->get()
or
Subject::orderBy('name','desc')->get()
Please or to participate in this conversation.