relations widgets for backpack
3.3.1
composer require izica/relations-widgets-for-backpack
關係面板
name
- 關係的名稱label
- 面板標籤backpack_crud
- 背包 CRUD 網址,buttons
(可選)- 設定false
以隱藏所有操作按鈕button_show
(可選)- 設定false
隱藏button_edit
(可選)- 設定false
隱藏visible
(可選)- 用於隱藏或顯示面板的關閉fields
(可選) - fields 數組,認為情況下從模型中的fillable
字段獲取列name
- 姓名label
- 用於字段closure
- 使用閉包代替名稱字段,visible
(可選)- 用於隱藏或顯示面板的關閉關係表
name
- (必填)關係名稱label
- 面板標籤relation_attribute
- (可選)用於傳遞button_create的url參數名稱search
- (可選) closure
,啟用搜尋輸入per_page
- (可選)啟用分頁,預設為null
backpack_crud
- 背包 CRUD 網址,buttons
(可選)- 設定false
以隱藏所有操作按鈕button_create
(可選)- 設定false
隱藏button_show
(可選)- 設定false
隱藏button_edit
(可選)- 設定false
隱藏button_delete
(可選)- 設定false
隱藏visible
(可選)- 用於隱藏或顯示面板的closure
columns
(可選) - columns array
,確認情況下從模型中的fillable
獲取列name
- 姓名label
- 用於字段closure
- 使用closure
而不是名稱欄位來傳遞值,belongsTo
, hasOne
use Backpack CRUD app Library Widget ;
protected function setupShowOperation ()
{
Widget:: add ([
' type ' => ' relation_panel ' ,
' name ' => ' account_contact ' ,
' label ' => ' Account contact info ' ,
' backpack_crud ' => ' accountcontact ' ,
' visible ' => function ( $ entry ){
return $ entry -> is_public_person ;
},
' buttons ' => false ,
' fields ' => [
[
' label ' => ' Birthdate ' ,
' closure ' => function ( $ entry ){
return date ( ' d.M.Y ' , $ entry -> birthdate );
}
],
[
' label ' => ' Contact phone ' ,
' name ' => ' contact_phone ' ,
],
[
' label ' => ' Contact email ' ,
' name ' => ' contact_email ' ,
],
[
' label ' => ' Address ' ,
' name ' => ' address.name ' ,
' visible ' => function ( $ entry ){
return !! $ entry -> address ;
}
],
],
])-> to ( ' after_content ' );
}
hasMany
protected function setupShowOperation ()
{
Widget:: add ([
' type ' => ' relation_table ' ,
' name ' => ' order_cargos ' ,
' label ' => ' Order cargo list ' ,
' backpack_crud ' => ' ordercargo ' ,
' visible ' => function ( $ entry ){
return $ entry -> order_cargos -> count () > 0 ;
},
' search ' => function ( $ query , $ search ) {
return $ query -> where ( ' name ' , ' like ' , " % { $ search } % " );
},
' relation_attribute ' => ' order_id ' ,
' button_create ' => true ,
' button_delete ' => false ,
' columns ' => [
[
' label ' => ' Type ' ,
' name ' => ' order_cargo_type.name ' ,
],
[
' label ' => ' Weight ' ,
' name ' => ' weight ' ,
],
[
' label ' => ' Value, $ ' ,
' closure ' => function ( $ entry ){
return "{ $ entry -> value } $ " ;
}
],
],
])-> to ( ' after_content ' );
}
您需要設定:
button_create
=> true
relation_attribute
=> attribute_name
接下來您需要新增到關係/選擇欄位default
值:
CRUD :: addField ([
' type ' => " relationship " ,
' name ' => ' order ' ,
' default ' => $ _GET [ ' order_id ' ] ?? null
]);