Skip to content

Commit db3ef90

Browse files
committed
add more examples for pivot select
1 parent 7ab6f0a commit db3ef90

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

6.x/crud-fields.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,20 +1782,29 @@ CRUD::field([
17821782

17831783
**That's it.** Backpack now will save those additional inputs on the pivot table.
17841784

1785-
Additionally, if you want to change something about the primary select, you can do that using the `pivotSelect` attribute:
1785+
#### Configuring the Pivot Select field
1786+
If you want to change something about the primary select (the pivot select field created by Backpack), you can do that using the `pivotSelect` attribute:
17861787

17871788
```php
17881789
CRUD::field([
17891790
'name' => 'companies',
17901791
'type' => "relationship",
17911792
'subfields' => [ ... ],
1792-
// ..
1793+
// you can use the same configurations you use in any relationship select
1794+
// like making it an ajax, constraining the options etc.
17931795
'pivotSelect'=> [
1794-
// 'ajax' => true,
17951796
'placeholder' => 'Pick a company',
17961797
'wrapper' => [
17971798
'class' => 'col-md-6',
17981799
],
1800+
// by default we call a $model->all(). you can configure it like in any other select
1801+
'options' => function($model) {
1802+
return $model->where('type', 'primary');
1803+
},
1804+
// note that just like any other select, enabling ajax will require you to provide an url for the field
1805+
// to fetch available options. You can use the FetchOperation or manually create the enpoint.
1806+
'ajax' => true,
1807+
'data_source' => backpack_url('fetch'),
17991808
],
18001809
]);
18011810
```

0 commit comments

Comments
 (0)