izica / select-tree-view-for-backpack
Select tree view
Installs: 53
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:Blade
Requires
- backpack/crud: ^5.0
README
Installation
composer require izica/select-tree-view-for-backpack
Usage
Table structure examples
catalog-category
- id
- name
- catalog_category_id
catalog-product
- id
- name
- catalog_category_id
Code
protected function setupCreateOperation() { CRUD::addField([ 'view_namespace' => 'izica::fields', // don't modify this field // REQUIRED 'type' => 'select_tree_view', 'label' => "Catalog category", 'name' => 'catalog_category_id', // in product view 'options' => CatalogCategory::get()->toArray(), // or in category view, with preventing loops on itself 'options' => CatalogCategory::whereNot('id', $this->crud->getCurrentEntryId())->get()->toArray(), // OPTIONAL 'options_parent_id' => 'catalog_category_id', // using value from 'name' param by default 'depth_prefix' => '. ', //default value 'depth_max' => 10, //default value 'options_root_id' => null, //default value 'options_sort_by' => 'name', //default value 'option_name' => 'name', //default value 'allows_null' => true, //default value 'default' => null, //default value ]); }
To prevent loops you