Skip to content

Commit 68bed4b

Browse files
Update validation.md
1 parent dcc8c32 commit 68bed4b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

3.1/imports/validation.md

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class UsersImport implements ToModel, WithValidation
3737

3838
// Above is alias for as it always validates in batches
3939
'*.1' => Rule::in(['[email protected]']),
40+
41+
// Can also use callback validation rules
42+
'0' => function($attribute, $value, $onFailure) {
43+
if ($value !== 'Patrick Brouwers') {
44+
$onFailure('Named is not Patrick Brouwers');
45+
}
46+
}
4047
];
4148
}
4249
}
@@ -181,6 +188,7 @@ try {
181188
$failure->row(); // row that went wrong
182189
$failure->attribute(); // either heading key (if using heading row concern) or column index
183190
$failure->errors(); // Actual error messages from Laravel validator
191+
$failure->values(); // The values of the row that has failed.
184192
}
185193
}
186194
```
@@ -247,6 +255,7 @@ foreach ($import->failures() as $failure) {
247255
$failure->row(); // row that went wrong
248256
$failure->attribute(); // either heading key (if using heading row concern) or column index
249257
$failure->errors(); // Actual error messages from Laravel validator
258+
$failure->values(); // The values of the row that has failed.
250259
}
251260
```
252261

0 commit comments

Comments
 (0)