發表文章

目前顯示的是有「admin」標籤的文章

今天再來處理 id 顯示 name 的問題

   用 php 抓資料是再簡單不過的事,用上 laravel 抓資料庫裏的資料應該也是,應該……,這次輪到 Show 的資料,使用那個不知為何一直連不上的外鍵,這次還是要處理數值轉出成名稱的問題。 工作環境:   laravel 7.*   dcat-admin 2.0.6-beta Show 資料列表用的是 show 區塊,像是 $show->field('foreign_id'); 再試了一下關係關聯的部份,結果還是撞牆,只能另(另)謀(闢)出(蹊)路(徑),胡搞蝦搞一番了。 $county = \App\Models\County::all()->pluck('name','id')->toArray(); $show->field('single')->using($county); 或是直接傳回 \App\Models\County::all()->pluck('name','id')->toArray() 又過了一關,仰賴 dcat 的 helper 還是得爬爬山。   收工!

今天還是要處理 id 轉換成 name

 用 php 抓資料是再簡單不過的事,用上 laravel 抓資料庫裏的資料應該也是,應該……,這次輪到 List 的資料,使用那個不知為何一直連不上的外鍵,這次還是要處理數值轉出成名稱的問題。 工作環境:   laravel 7.*   dcat-admin 2.0.6-beta List 資料列表用的是 grid 區塊,像是 $grid->column('foreign_id'); 再試了一下關係關聯的部份,結果還是撞牆,只能另(另)謀(闢)出(蹊)路(徑),胡搞蝦搞一番了。 $grid->column('foreign_id')->display(function($foreign_id){     $counties = \App\Models\County::all()->pluck('name','id');     $output = $counties[$foreign_id];     return $output; }); 或是直接 \App\Models\County::find($foreign_id)->name;  不論是哪一種 scaffold 都有崁,只希望 dcat 的崎嶇少一點,畢竟目前為止,它的介面最好用啊。   收工!

就只是想把 name id 抓出來倒到 selection 裏

用 php 抓資料是再簡單不過的事,用上 laravel 抓資料庫裏的資料應該也是,應該…… 工作環境:   laravel 7.*   dcat-admin 2.0.6-beta $form->selction('field_name')->options($options); 就是為了那個 $options 看文件,又要設關聯,又要改 new 啟始的條件,要加 ::with(['foreign_table']),奈何,不是路徑不對,不然 get() 時少了變數,要不就找不到 Controller, Model, object, method, variable ...........,啊不是說很簡單 )(*^%$%*()_)(*&^(*&^&(_)*& 結果還真的很簡單,跳過以上那些個說明,直接: $options = \App\Models\ModelName::all()->pluck('name','id'); //記得那個一開始的 \ 不能少了! 結果這個 options 的產出,官網文檔、演示站就是沒有,可能太低小下,略了! 青春也略了!   收工!