MySQL表中的同名字段相互覆盖 - Laravel

So, I need to do a join between 2 tables - items and categories.

I'm coding in Laravel and here is what I have:

$items = DB::table('items')
            ->join('categories', 'categories.id', '=', 'items.category_id')
            ->get();

And then I get some results like these:

{
  id: 3,
  barcode: "0002",
  category_id: "4",
  price: 200,
  in_use: 1,
  serial_number: 1112,
  model: "Toshiba",
  condition_id: 3,
  person_id: 1,
  comments: "A monitor that is usually connected to a laptop.",
  created_at: "2017-03-28 19:50:02",
  updated_at: "2017-03-28 19:50:02",
  name: "monitor",
},
{
  id: 3,
  barcode: "0003",
  category_id: "4",
  price: 300,
  in_use: 1,
  serial_number: 11342,
  model: "Toshiba",
  condition_id: 3,
  person_id: 1,
  comments: "A monitor that is usually connected to a laptop.",
  created_at: "2017-03-28 19:50:02",
  updated_at: "2017-03-28 19:50:02",
  name: "monitor",
},

Both tables have some fields that have the same name, such as id created_at and updated_at. The problem is that, because they have the same name, the values of the one table overwrite the values of the other table. How do I get the 2nd table values to not overwrite the values from the first one when they have the same column name? Or, even better, how do I get both values back (from both tables)? Maybe using the AS keyword somehow?

Thanks for the help.

Yes, you should use the AS keyword for each duplicate fields

This is how it works :

$items = DB::table('items')
        ->join('categories', 'categories.id', '=', 'items.category_id')
        ->select('field1', 'field2 as field2name', 'field3')
        ->get();

Note : for the fields that have the same name, use it this way : 'table.field'