如下圖範例,在最後->get()之後加上->keyBy('id'),可以把id這個欄位變成key,在資料處理過程很好用。 keyBy multiple columns:->keyBy(function ($item) { return $item['id_1'] . '_' . $item['id_2'];}); 本筆記參考:1. https://stackoverflow.com/questions/26865877/laravel-eloquent-return-array-key-as-the-fields-id2. https://www.itsolutionstuff.com/post/laravel-collection-keyby-method-exampleexample.html