Skip to content

Commit fbb1163

Browse files
committed
update readme
1 parent a58e14a commit fbb1163

File tree

1 file changed

+51
-36
lines changed

1 file changed

+51
-36
lines changed

README.md

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![Quality Score][ico-code-quality]][link-code-quality]
99
[![Total Downloads][ico-downloads]][link-downloads]
1010

11-
This is a package for [Laravel Backpack](https://laravel-backpack.readme.io/docs) and provides CRUD field types which allow to create a related CRUD entity on-the-fly while adding/editing another.
11+
This is a package for [Laravel Backpack](https://laravel-backpack.readme.io/docs) and provides CRUD field types which allow to create and edit a related CRUD entity on-the-fly while adding/editing another.
1212

1313
![Screenshot](https://webfactor.de/files/modal_1.png)
1414

@@ -55,11 +55,12 @@ CRUD::resource('entity', 'EntityCrudController')->with(function () {
5555
});
5656
```
5757

58-
The trait/route will handle three situations for you:
58+
The trait/route will handle the following requests for you:
5959

6060
- search on triggered entity
61-
- retrieve the HTML for the modal
61+
- retrieve the HTML for the create and edit modal
6262
- store entity from modal
63+
- update entity from modal
6364

6465
### Available Fields
6566

@@ -68,15 +69,35 @@ There are two field types available in this package which allow you an instant c
6869
- [select2_from_ajax](https://laravel-backpack.readme.io/docs/crud-fields#section-select2_from_ajax)
6970
- [select2_from_ajax_multiple](https://laravel-backpack.readme.io/docs/crud-fields#section-select2_from_ajax_multiple)
7071

71-
To use instant creation capability of these field types you have to add the `on-the-fly` key and set a name for the entity.
72+
For `select2_from_ajax` also "edit" is available.
7273

74+
### Field Definition
75+
76+
Please set the `$ajaxEntity` property by using the setter in the `setup()`-method of the (foreign) EntityCrudController that is **triggered** by an "instant field":
77+
78+
```php
79+
<?php
80+
81+
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
82+
83+
class EntityCrudController extends CrudController
84+
{
85+
use InstantFields;
86+
87+
public function setup()
88+
{
89+
// other Backpack options
90+
91+
$this->setAjaxEntity('entity');
92+
93+
// fields/columns definitions
94+
}
95+
}
7396
```
74-
'on_the_fly' => [
75-
'entity' => 'entity' // e.g. user, contact, company, job etc...
76-
]
77-
```
97+
98+
In the field definition of the `EntityCrudController` where your instant field is setup you will have to set the above name in the `on_the_fly`-Array.
7899

79-
If you use Laravel Backpack Crud >=3.4.11 you don't have to publish the provided fields, you can use them directly from the package by using the `view_namespace` key.
100+
> Note: If you use Laravel Backpack Crud >=3.4.11 you don't have to publish the provided fields, you can use them directly from the package by using the `view_namespace` key.
80101
81102
Example:
82103

@@ -93,39 +114,22 @@ Example:
93114
'pagination' => 20, // optional, default: 10
94115
'minimum_input_length' => 0,
95116
'on_the_fly' => [
96-
'entity' => 'entity',
97-
'attribute' => 'name' // optional, default: name
117+
'entity' => 'entity', // e. g. user, contact, company etc...
118+
119+
// optional:
120+
121+
'create' => false
122+
'edit' => false
123+
'create_modal' => 'path to custom create modal'
124+
'edit_modal' => 'path to custom edit modal'
125+
'attribute' => '...' // see auto-fill below in readme
98126
],
99127
'dependencies' => ['field1', 'field2'...], // optional, resets this field when changing the given ones
100128
],
101129
```
102130

103131
Instant Fields will try to auto-fill the select2 input after creating a new entry. It will assume that an input field exists with the name `name` and will use its value for the triggered ajax search. If you want to use another field for this, just add `attribute` to the `on_the_fly`-array containing the field name you want to use.
104132

105-
## Multiple instant fields
106-
107-
If you want to use more than one instant field in a CrudController you have to set the `$ajaxEntity` property by using the setter in the `setup()`-method of the EntityCrudController that is triggered by an "instant field". This has to be the same name as in the field definition:
108-
109-
```php
110-
<?php
111-
112-
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
113-
114-
class EntityCrudController extends CrudController
115-
{
116-
use InstantFields;
117-
118-
public function setup()
119-
{
120-
// other Backpack options
121-
122-
$this->setAjaxEntity('entity');
123-
124-
// fields/columns definitions
125-
}
126-
}
127-
```
128-
129133
## List view
130134

131135
With this package your are also able to add a create button for the foreign CRUD entity in your list view of Backpack! Just add the following line in your `EntityCrudController`:
@@ -192,7 +196,7 @@ If needed you are free to use the `data_source` attribute from the original fiel
192196

193197
### Request validation
194198

195-
You can also use Request Validation! Just set the `$ajaxStoreRequest` property by using the provided setter method:
199+
You can also use Request Validation! Just set the `$ajaxStoreRequest` and/or `$ajaxUpdateRequest` property by using the provided setter method:
196200

197201
```php
198202
<?php
@@ -209,11 +213,22 @@ class EntityCrudController extends CrudController
209213

210214
$this->setAjaxEntity('entity');
211215
$this->setAjaxStoreRequest(\RequestNamespace\StoreRequest::class);
216+
$this->setAjaxUpdateRequest(\RequestNamespace\UpdateRequest::class);
212217

213218
// fields/columns definitions
214219
}
215220
}
216221
```
222+
### Auto-fill after store/update
223+
224+
Instant Fields will try to auto-fill the select2 input after creating a new entry. It will assume that an input field exists with the name `name` and will use its value for the triggered ajax search. If you want to use another field for this, just add `attribute` to the `on_the_fly`-array containing the field name you want to use:
225+
226+
```
227+
'on_the_fly' => [
228+
'entity' => 'entity',
229+
'attribute' => 'company'
230+
]
231+
```
217232

218233
### Fields
219234

0 commit comments

Comments
 (0)