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
]);