Skip to content

Commit 375a861

Browse files
committed
add eager load docs to update operation
1 parent 20a6218 commit 375a861

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

6.x/crud-operation-update.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ To use the Update operation, you must:
5656
```php
5757
// add a field only to the Update operation
5858
$this->crud->addField($field_definition_array);
59-
// add a field to both the Update and Update operations
60-
$this->crud->addField($field_definition_array);
6159
```
6260

6361
**Step 2. Specify which FormRequest file to use for validation and authorization**, inside your ```setupUpdateOperation()``` method. You can pass the same FormRequest as you did for the Create operation if there are no differences. If you need separate validation for Create and Update [look here](#separate-validation).
@@ -67,6 +65,13 @@ $this->crud->setValidation(StoreRequest::class);
6765

6866
For more on how to manipulate fields, please read the [Fields documentation page](/docs/{{version}}/crud-fields). For more on validation rules, check out [Laravel's validation docs](https://laravel.com/docs/master/validation#available-validation-rules).
6967

68+
**Step 3. (optional recommended) eager load relationships**. If you're displaying relationships in your fields, you might want to eager load them to avoid the N+1 problem. You can do that in the `setupUpdateOperation()` method:
69+
70+
```php
71+
$this->crud->setOperationSetting('eagerLoadRelationships', true);
72+
```
73+
Note: You can enable this setting globally for all your cruds in the `config/backpack/operations/update.php` file.
74+
7075
<a name="how-it-works"></a>
7176
## How It Works
7277

0 commit comments

Comments
 (0)