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
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.
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.
72
73
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
+
}
73
96
```
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.
78
99
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.
80
101
81
102
Example:
82
103
@@ -90,35 +111,50 @@ Example:
90
111
'entity' => 'entity',
91
112
'attribute' => 'name',
92
113
'placeholder' => 'Choose',
114
+
'pagination' => 20, // optional, default: 10
93
115
'minimum_input_length' => 0,
94
116
'on_the_fly' => [
95
-
'entity' => 'entity',
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
96
126
],
127
+
'dependencies' => ['field1', 'field2'...], // optional, resets this field when changing the given ones
97
128
],
98
129
```
99
130
100
-
## Multiple instant fields
131
+
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.
132
+
133
+
## List view
101
134
102
-
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:
135
+
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`:
103
136
104
137
```php
105
138
<?php
106
139
107
-
use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
108
-
109
-
class EntityCrudController extends CrudController
110
-
{
111
-
use InstantFields;
112
-
113
-
public function setup()
114
-
{
115
-
// other Backpack options
140
+
$this->addInstantCreateButtonToList(
141
+
$entity, // foreign entity
142
+
$content, // content of the button
143
+
$entity_id, // the name of the ID of the current entity will be forwarded by this
144
+
$class, // optional, default: 'btn btn-xs btn-default', the css class of the button
145
+
$position, // optional, default: beginning, the position of the button in the line
146
+
$button_view // optional, you can override the used button blade by your own
147
+
);
116
148
117
-
$this->setAjaxEntity('entity');
118
-
119
-
// fields/columns definitions
120
-
}
121
-
}
149
+
// Example:
150
+
151
+
$this->addInstantCreateButtonToList(
152
+
'order',
153
+
'<iclass="fa fa-cart-plus"></i>',
154
+
'task_id',
155
+
'btn btn-sm btn-info',
156
+
'end'
157
+
);
122
158
```
123
159
124
160
## Customization
@@ -143,22 +179,24 @@ The "instant field" triggers the `ajaxIndex()` of the `EntityCrudController` whe
143
179
By adding `search_logic` to the field defintion you can implement your own searching behavior:
`Collecion $form` is an optional parameter and provides all current values of your CRUD form. You can use it to manipulate your search depending on actual inputs and in combination with `dependencies` (see [Backpack Documentation](https://backpackforlaravel.com/docs/3.5/crud-fields#select2_from_ajax))
190
+
153
191
Furthermore you can then use `attibute` to display enriched values in the dropdown by using an accessor on the model.
154
192
155
193
### Search data source
156
194
157
-
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.
195
+
If needed you are free to use the `data_source`and `method` attributes from the original field blades which come with Laravel Backpack. This is the URL that is triggered by the select2 field for searching.
158
196
159
197
### Request validation
160
198
161
-
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:
162
200
163
201
```php
164
202
<?php
@@ -175,11 +213,22 @@ class EntityCrudController extends CrudController
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:
0 commit comments