Skip to content

Commit

Permalink
add more examples for pivot select
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Aug 11, 2023
1 parent 7ab6f0a commit db3ef90
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions 6.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -1782,20 +1782,29 @@ CRUD::field([

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

Additionally, if you want to change something about the primary select, you can do that using the `pivotSelect` attribute:
#### Configuring the Pivot Select field
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:

```php
CRUD::field([
'name' => 'companies',
'type' => "relationship",
'subfields' => [ ... ],
// ..
// you can use the same configurations you use in any relationship select
// like making it an ajax, constraining the options etc.
'pivotSelect'=> [
// 'ajax' => true,
'placeholder' => 'Pick a company',
'wrapper' => [
'class' => 'col-md-6',
],
// by default we call a $model->all(). you can configure it like in any other select
'options' => function($model) {
return $model->where('type', 'primary');
},
// note that just like any other select, enabling ajax will require you to provide an url for the field
// to fetch available options. You can use the FetchOperation or manually create the enpoint.
'ajax' => true,
'data_source' => backpack_url('fetch'),
],
]);
```
Expand Down

0 comments on commit db3ef90

Please sign in to comment.