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
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.
26
+
27
+
```php
28
+
<?php
29
+
30
+
use Webfactor\Laravel\Backpack\InstantFields\CanBeCreatedOnTheFly;
31
+
32
+
class EntityCrudController extends CrudController
33
+
{
34
+
use CanBeCreatedOnTheFly;
35
+
36
+
//
37
+
}
38
+
```
39
+
40
+
This trait provides all needed route entry points methods and ajax response methods.
41
+
42
+
### Routes
43
+
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:
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 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.
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:
100
+
25
101
```php
26
102
<?php
27
103
28
-
// to be added
104
+
use Webfactor\Laravel\Backpack\InstantFields\CanBeCreatedOnTheFly;
105
+
106
+
class EntityCrudController extends CrudController
107
+
{
108
+
use CanBeCreatedOnTheFly;
109
+
110
+
public function setup()
111
+
{
112
+
// other Backpack options
113
+
$this->setAjaxEntity('name_of_entity');
114
+
115
+
// fields/columns definitions
116
+
}
117
+
}
118
+
```
119
+
120
+
### Field definition
121
+
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.
If you need a different search behavior just overwrite the `ajaxIndex()` method in your `EntityCrudController` and write your own search logic.
136
+
137
+
### Request validation
138
+
139
+
You can also use Request Validation! Just copy the `ajaxStore()` method to your `EntityCrudController` and replace `Request` by your desired request (usually just `StoreRequest`).
140
+
141
+
### Fields
142
+
143
+
Publish the fields in your project and modify functionality
0 commit comments