relations widgets for backpack
3.3.1

composer require izica/relations-widgets-for-backpack


painel_relacionamento
name - nome da relaçãolabel - etiqueta do painelbackpack_crud - URL da mochila crud,buttons (opcional) - defina false para ocultar todos os botões de açãobutton_show (opcional) - defina false para ocultarbutton_edit (opcional) - defina false para ocultarvisible (opcional) - fechamento para ocultar ou mostrar painelfields (opcional) - array de campos, por padrão obtém colunas fillable no modeloname - nomelabel - para campoclosure - use fechamento em vez do campo de nome,visible (opcional) - fechamento para ocultar ou mostrar paineltabela_relação
name - (obrigatório) nome da relaçãolabel - etiqueta do painelrelation_attribute - (opcional) usado para passar o nome do parâmetro de URL para button_createsearch - closure (opcional), permite entrada de pesquisaper_page - (opcional) ativa a paginação, null por padrãobackpack_crud - URL da mochila crud,buttons (opcional) - defina false para ocultar todos os botões de açãobutton_create (opcional) - defina false para ocultarbutton_show (opcional) - defina false para ocultarbutton_edit (opcional) - defina false para ocultarbutton_delete (opcional) - defina false para ocultarvisible (opcional) - closure para ocultar ou mostrar painelcolumns (opcional) - array de colunas, por padrão obtém colunas fillable no modeloname - nomelabel - para campoclosure - use closure em vez do campo de nome para passar valor, 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 ' );
}Você precisa definir:
button_create => truerelation_attribute => attribute_name Em seguida, você precisa adicionar ao valor default do campo relação/seleção:
CRUD :: addField ([
' type ' => " relationship " ,
' name ' => ' order ' ,
' default ' => $ _GET [ ' order_id ' ] ?? null
]);