diff --git a/3.1/imports/concerns.md b/3.1/imports/concerns.md index 16486df..ea83906 100644 --- a/3.1/imports/concerns.md +++ b/3.1/imports/concerns.md @@ -23,6 +23,8 @@ pageClass: no-toc |`Maatwebsite\Excel\Concerns\WithCustomCsvSettings`| Allows to run custom Csv settings for this specific importable. | [Custom CSV Settings](/3.1/imports/custom-csv-settings.html) | |`Maatwebsite\Excel\Concerns\WithStartRow`| Define a custom start row. | | |`Maatwebsite\Excel\Concerns\WithProgressBar`| Shows a progress bar when uploading via the console. | [Progress Bar](/3.1/imports/progress-bar.html) | +|`Maatwebsite\Excel\Concerns\WithUpsert`| Allows to upsert models. | [Upserting models](/3.1/imports/model.html#upserting-models) | +|`Maatwebsite\Excel\Concerns\WithUpsertColumns`| Allows upsert columns definition. | [Upserting with specific columns](/3.1/imports/model.html#upserting-with-specific-columns) | |`Maatwebsite\Excel\Concerns\WithValidation`| Validates each row against a set of rules. | [Row Validation](/3.1/imports/validation.html) | |`Maatwebsite\Excel\Concerns\SkipsOnFailure`| Skips on validation errors. | [Row Validation](/3.1/imports/validation.html#skipping-failures) | |`Maatwebsite\Excel\Concerns\SkipsOnError`| Skips on database exceptions. | [Row Validation](/3.1/imports/validation.html#skipping-errors) | diff --git a/3.1/imports/model.md b/3.1/imports/model.md index 31a099e..d8ab5e7 100644 --- a/3.1/imports/model.md +++ b/3.1/imports/model.md @@ -50,6 +50,25 @@ In the example above, if a user already exists with the same email, the row will All databases except SQL Server require the `uniqueBy` columns to have a "primary" or "unique" index. ::: +### Upserting with specific columns + +By default, `upsert`, in case of updating, will update all columns that match model's attributes. However, if you need to update only specific column(s) during `upsert`, you can also implement the `WithUpsertColumns` concern. + +```php +class UsersImport implements ToModel, WithUpserts, WithUpsertColumns +{ + /** + * @return array + */ + public function upsertColumns() + { + return ['name', 'role']; + } +} +``` + +In this example, if a user already exists, only "name" and "role" columns will be updated. + ## Skipping rows In case you want to skip a row, you can return null.