目前,$mymodel->getDictionary();
回報:Laravel雄辯:getDictionary與對象的值作爲結果的值
我所尋找的是這樣的:
"7gct5YaTvuxBmY2" => "Leadership",
"7NrXZepqczMSHqM" => "...",
"..." => "...",
...
我成功的唯一途徑這是:
$construct_obj = OrganizationalConstruct::where('is_root', 0)->where('organization_id', $this->current_company->company_id)->get();
$constructs = [];
$constructs[''] = '';
for ($i = 0; $i < count($construct_obj); $i++) {
$constructs[$construct_obj[$i]->organizational_construct_id] = $construct_obj[$i]->construct_name;
}
是否有一個ea更方便獲得格式"key" => "speific-column-value"
?
我曾嘗試:
- keyBy
- 名單
- getDictionary
- 地圖
謝謝!奇蹟般有效 – Haring10