You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-26Lines changed: 47 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,9 @@
10
10
11
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.
In the EntityCrudController that is supposed to PROVIDE instant creation (not in the CrudController where you want to USE instant fields!) you have to embed the `CanBeCreatedOnTheFly` trait from this package.
28
+
For simplicity add the `InstantFields` trait from this package to all EntityCrudControllers which are supposed to provide "instant fields" or are triggered by "instant fields".
26
29
27
30
```php
28
31
<?php
29
32
30
-
use Webfactor\Laravel\Backpack\InstantFields\CanBeCreatedOnTheFly;
33
+
use Webfactor\Laravel\Backpack\InstantFields\Instantfields;
31
34
32
35
class EntityCrudController extends CrudController
33
36
{
34
-
use CanBeCreatedOnTheFly;
37
+
use InstantFields;
35
38
36
39
//
37
40
}
@@ -41,30 +44,34 @@ This trait provides all needed route entry points methods and ajax response meth
41
44
42
45
### Routes
43
46
44
-
in your routes file you have to add three additional routes for you`CRUD::resource`. For clarity we recommend to use the `with()` helper:
47
+
in your routes file you have to add one additional route in your`CRUD::resource` for each Entity that uses the packages trait. For clarity we recommend to use the `with()` helper:
The trait/route will handle three situations for you:
58
+
59
+
- search on triggered entity
60
+
- retrieve the HTML for the modal
61
+
- store entity from modal
62
+
56
63
### Available Fields
57
64
58
65
There are two field types available in this package which allow you an instant creation of related models (1-n and n-m). They are modified versions of the equivalent field types that already exist in Laravel Backpack:
If you want to use more than one instant field in a CrudController you have to define separate names for each so that JQuery is able to trigger the modals in the right way.
96
-
97
-
### EntityCrudController
98
-
99
-
In the EntityCrudController that provides instant creation you have to set the `$ajaxEntity` property by using the setter in the `setup()`-method:
101
+
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:
100
102
101
103
```php
102
104
<?php
103
105
104
-
use Webfactor\Laravel\Backpack\InstantFields\CanBeCreatedOnTheFly;
106
+
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
105
107
106
108
class EntityCrudController extends CrudController
107
109
{
108
-
use CanBeCreatedOnTheFly;
110
+
use InstantFields;
109
111
110
112
public function setup()
111
113
{
112
114
// other Backpack options
113
-
$this->setAjaxEntity('name_of_entity');
115
+
116
+
$this->setAjaxEntity('entity');
114
117
115
118
// fields/columns definitions
116
119
}
117
120
}
118
121
```
119
122
120
-
### Field definition
123
+
## Customization
124
+
125
+
### Modal view
121
126
122
-
In the field definition you have to add `entity` to the `on-the-fly` key and give it the exact same name as in the EntityCrudController above.
127
+
By default the modal is loaded automatically by using `entity` in `on_the_fly` of the field definition resulting in `backpack_url($field['on_the_fly']['entity']).'/ajax/create'` in the field blade.
128
+
129
+
You can overwrite this behavior by setting a `create_view` attribute:
The "instant field" triggers the `ajaxIndex()` of the `EntityCrudController` where the field is defined and uses the fields `model` and `attribute` parameters to perform the search on the foreign model.
141
+
142
+
By adding `search_logic` to the field defintion you can implement your own searching behavior:
Furthermore you can then use `attibute` to display enriched values in the dropdown by using an accessor on the model.
132
153
133
-
### Search behavior
154
+
### Search data source
134
155
135
-
If you need a different search behavior just overwrite the `ajaxIndex()` method in your `EntityCrudController` and write your own search logic.
156
+
If needed you are free to use the `data_source` attribute from the original field blades which come with Laravel Backpack. This is the URL that is triggered by the select2 field for searching.
0 commit comments