如何在laravel / eloquent中访问或检索关联数组的键值?

I used the query builder to select an item from my DB, now if I do DD ($item) I get an associative array like:

array:1 [
  0 => {
    "id": 1,
    "itm_id": 615,
    "itm_val_id": 5,
    "created_at": "2015-10-26 09:42:23",
    "updated_at": "2015-10-26 09:42:23"
  }
]

I need to attach the ID to the user in a pivot table, the question is: how do I get that id??

that doesn't work, but this works:

Auth::user()->item()->attach($item[0]->id);

You can use attach like this:

Auth::user()->item()->attach($item[0]->id);

Auth::user()->item()->attach([1 => ['itm_id' => $item[0]->id], $item[0]->id]);

You can read more about many to many relation in Laravel docs.