izica/relations-widgets-for-backpack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

izica/relations-widgets-for-backpack

最新稳定版本:3.3.2

Composer 安装命令:

composer require izica/relations-widgets-for-backpack

包简介

Widgets for preview model relations in laravel backpack

README 文档

README

  1. Installation
  2. Screenshots
  3. Features
  4. Documentation
  5. Usage
  6. How to enable creating related model

3.0 Whats new:

  • relation_table search input
  • relation_table create button with relation attribute reference
  • relation_table pagination

Alt text

Installation

composer require izica/relations-widgets-for-backpack

Screenshots

Alt text Alt text

Features

  • use widgets for showing relations in show operation
  • show or hide panels or fields by conditions
  • build field value by closure
  • use dot orm notation for accessing relation fields

Documentation

  • relation_panel

    • name - name of relation
    • label - panel label
    • backpack_crud - backpack crud url,
    • buttons (optional) - set false to hide all action buttons
    • button_show (optional) - set false to hide
    • button_edit (optional) - set false to hide
    • visible (optional) - closure for hiding or showing panel
    • fields (optional) - fields array, by default get columns from fillable in model
      • name - name
      • label - for field
      • closure - use closure instead of name field,
      • visible(optional) - closure for hiding or showing panel
  • relation_table

    • name - (required) name of relation
    • label - panel label
    • relation_attribute - (optional) used for passing url parameter name for button_create
    • search - (optional) closure, enables search input
    • per_page - (optional) enables pagination, null by default
    • backpack_crud - backpack crud url,
    • buttons (optional) - set false to hide all action buttons
    • button_create (optional) - set false to hide
    • button_show (optional) - set false to hide
    • button_edit (optional) - set false to hide
    • button_delete (optional) - set false to hide
    • visible (optional) - closure for hiding or showing panel
    • columns (optional) - columns array, by default get columns from fillable in model
      • name - name
      • label - for field
      • closure - use closure instead of name field for passing value,

Usage

Relation panel

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');
}

Relation table

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');
}

How to enable creating related model

You need to set:

  • button_create => true
  • relation_attribute => attribute_name

Next you need to add to relation/select field default value:

    CRUD::addField([
        'type' => "relationship",
        'name' => 'order',
        'default' => $_GET['order_id'] ?? null
    ]);

统计信息

  • 总下载量: 24.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 4
  • Forks: 14
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-08