{"id":18604273,"url":"https://github.com/izica/relations-widgets-for-backpack","last_synced_at":"2025-07-17T17:35:49.505Z","repository":{"id":45921878,"uuid":"278076594","full_name":"izica/relations-widgets-for-backpack","owner":"izica","description":"Views/widgets for preview laravel relations in laravel backpack","archived":false,"fork":false,"pushed_at":"2023-07-02T16:22:19.000Z","size":318,"stargazers_count":29,"open_issues_count":1,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-11T12:36:59.047Z","etag":null,"topics":["backpack","laravel","laravel-backpack","laravel-package","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"Blade","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izica.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-08T11:56:33.000Z","updated_at":"2024-10-10T11:13:18.000Z","dependencies_parsed_at":"2022-09-22T14:41:01.606Z","dependency_job_id":null,"html_url":"https://github.com/izica/relations-widgets-for-backpack","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Frelations-widgets-for-backpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Frelations-widgets-for-backpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Frelations-widgets-for-backpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Frelations-widgets-for-backpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izica","download_url":"https://codeload.github.com/izica/relations-widgets-for-backpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223444736,"owners_count":17146167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backpack","laravel","laravel-backpack","laravel-package","php","php-library"],"created_at":"2024-11-07T02:17:15.058Z","updated_at":"2024-11-07T02:17:15.630Z","avatar_url":"https://github.com/izica.png","language":"Blade","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Laravel Backpack Relations Widgets\n1. [Installation](#installation)\n2. [Screenshots](#screenshots)\n3. [Features](#features)\n4. [Documentation](#documentation)\n5. [Usage](#usage)\n5. [How to enable creating related model](#how-to-enable-creating-related-model)\n\n### 3.0 Whats new:\n* relation_table search input\n* relation_table create button with relation attribute reference\n* relation_table pagination\n\n![Alt text](screenshots/relation_table_with_options.png?raw=true \"relation_table_with_options\")\n\n### Installation\n```\ncomposer require izica/relations-widgets-for-backpack\n```\n\n### Screenshots\n\n![Alt text](screenshots/relation_panel.png?raw=true \"relation_panel\")\n![Alt text](screenshots/relation_table.png?raw=true \"relation_table\")\n\n### Features\n* use widgets for showing relations in show operation\n* show or hide panels or fields by conditions\n* build field value by closure\n* use dot orm notation for accessing relation fields\n\n### Documentation\n* relation_panel\n    * `name` - name of relation\n    * `label` - panel label\n    * `backpack_crud` - backpack crud url,\n    * `buttons` (optional) - set `false` to hide all action buttons\n    * `button_show` (optional) - set `false` to hide\n    * `button_edit` (optional) - set `false` to hide\n    * `visible` (optional) - closure for hiding or showing panel\n    * `fields` (optional) - fields array, by default get columns from `fillable` in model\n        * `name` - name\n        * `label` - for field\n        * `closure` - use closure instead of name field,\n        * `visible`(optional) - closure for hiding or showing panel\n        \n* relation_table\n    * `name` - (required) name of relation\n    * `label` - panel label\n    * `relation_attribute` - (optional) used for passing url parameter name for button_create\n    * `search` - (optional) `closure`, enables search input\n    * `per_page` - (optional) enables pagination, `null` by default\n    * `backpack_crud` - backpack crud url,\n    * `buttons` (optional) - set `false` to hide all action buttons\n    * `button_create` (optional) - set `false` to hide\n    * `button_show` (optional) - set `false` to hide\n    * `button_edit` (optional) - set `false` to hide\n    * `button_delete` (optional) - set `false` to hide\n    * `visible` (optional) - `closure` for hiding or showing panel\n    * `columns` (optional) - columns `array`, by default get columns from `fillable` in model\n        * `name` - name\n        * `label` - for field\n        * `closure` - use `closure` instead of name field for passing value,\n        \n### Usage\n\n#### Relation panel\n`belongsTo`, `hasOne`\n\n```php\nuse Backpack\\CRUD\\app\\Library\\Widget;\n\nprotected function setupShowOperation()\n{\n    Widget::add([\n        'type'           =\u003e 'relation_panel',\n        'name'           =\u003e 'account_contact',\n        'label'          =\u003e 'Account contact info',\n        'backpack_crud'  =\u003e 'accountcontact',\n        'visible' =\u003e function($entry){\n            return $entry-\u003eis_public_person;\n        },\n        'buttons' =\u003e false,\n        'fields'         =\u003e [\n            [\n                'label' =\u003e 'Birthdate',\n                'closure' =\u003e function($entry){\n                    return date('d.M.Y', $entry-\u003ebirthdate);\n                }\n            ],\n            [\n                'label' =\u003e 'Contact phone',\n                'name'  =\u003e 'contact_phone',\n            ],\n            [\n                'label' =\u003e 'Contact email',\n                'name'  =\u003e 'contact_email',\n            ],\n            [\n                'label' =\u003e 'Address',\n                'name'  =\u003e 'address.name',\n                'visible' =\u003e function($entry){\n                    return !!$entry-\u003eaddress;\n                }       \n            ],\n        ],\n    ])-\u003eto('after_content');\n}\n\n```\n\n#### Relation table\n`hasMany`\n\n```php\nprotected function setupShowOperation()\n{\n    Widget::add([\n        'type'           =\u003e 'relation_table',\n        'name'           =\u003e 'order_cargos',\n        'label'          =\u003e 'Order cargo list',\n        'backpack_crud'  =\u003e 'ordercargo',\n        'visible' =\u003e function($entry){\n            return $entry-\u003eorder_cargos-\u003ecount() \u003e 0;\n        },\n        'search' =\u003e function ($query, $search) {\n            return $query-\u003ewhere('name', 'like', \"%{$search}%\");\n        },\n        'relation_attribute' =\u003e 'order_id',\n        'button_create' =\u003e true,\n        'button_delete' =\u003e false,\n        'columns' =\u003e [\n            [\n                'label' =\u003e 'Type',\n                'name'  =\u003e 'order_cargo_type.name',\n            ],\n            [\n                'label' =\u003e 'Weight',\n                'name'  =\u003e 'weight',\n            ],\n            [\n                'label' =\u003e 'Value, $',\n                'closure' =\u003e function($entry){\n                    return \"{$entry-\u003evalue}$\";\n                }\n            ],\n        ],\n    ])-\u003eto('after_content');\n}\n\n```\n\n### How to enable creating related model\nYou need to set:\n* `button_create` =\u003e `true`\n* `relation_attribute` =\u003e `attribute_name`\n\nNext you need to add to relation/select field `default` value:\n```php\n    CRUD::addField([\n        'type' =\u003e \"relationship\",\n        'name' =\u003e 'order',\n        'default' =\u003e $_GET['order_id'] ?? null\n    ]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizica%2Frelations-widgets-for-backpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizica%2Frelations-widgets-for-backpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizica%2Frelations-widgets-for-backpack/lists"}