Level 50
You can use select in order to select from which table you want to pick the columns with the same name:
DB::table('table1')->join('table2','table1.id','=','table2.table1_id')->orderByRaw('position')->select('table1.*')->get()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi! I've a sql Query DB::table('table1')->join('table2','table1.id','=','table2.table1_id')->orderByRaw('position')->get();
In both tables, table1 and table2 is a column id. After the request I get a collection with one attribute id, the id attribute ist from table2 Why? How can I change this to id from table1? So I need something like table1.id or?
You can use select in order to select from which table you want to pick the columns with the same name:
DB::table('table1')->join('table2','table1.id','=','table2.table1_id')->orderByRaw('position')->select('table1.*')->get()
Please or to participate in this conversation.