-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array upload validation & bugs #13779
Comments
i found a solution-ish for the array errors not showing up $rules = [
'title' => 'required|unique:posts|max:255',
'description' => 'required',
'photo.*' => 'required|mimes:jpg,jpeg,png,bmp|max:4096'
];
$validate = Validator::make($request->all(), $rules);
if ($validate->fails()) {
foreach ($validate->errors()->getMessages() as $k => $v) {
// we search for any error that has "word.number"
$last= [];
if (preg_match("/\w+\.\d+/", $k)) {
// save into new array
$last[] = $v;
}
}
// flatten the array into one level
$res = array_flatten($last);
$validate->errors()->add('photo_err', $res);
throw new ValidationException(
$validate,
redirect()->back()
->withInput($request->input())
->withErrors($validate->errors()->getMessages())
);
} now the
so make a presenter public function test($array)
{
$array['photo_err'] = call_user_func_array('array_merge', $array['photo_err']);
return $array['photo_err'];
} and in the view @inject('test','The-Class-name')
@if ($errors->getMessages())
@foreach ($test->test($errors->getMessages()) as $one)
<li>{{ $one }}</li>
@endforeach
@endif |
update: |
I think the memory issue is not laravel related, for the other problem you have I don't seem to get it. Can you please share more details with a sample code? Better, can you please write a failing test? |
@themsaid currently when u validate an array how do u retrive the errors of the failed files ? , cuz the old |
OSX 10.11.5
brew PHP 7.0.7
Lara v5.2.34
when i try to upload multiple files i get an error,
which come up from time to time and the solution would be adding
ini_set('memory_limit', '500M');
in the routes.php file.the other issue is related more to the validation it self
and in the view 'btw the docs doesnt have how to display validated array errors, it only show how to write the validation logic"
which doesnt work anymore because the returned array doesnt always return the item
photo.0
but havephoto.1/2/etc...
so i cant view those errors anymoreand here is the returned validation
also as u can see the each photo now has error of 0 , where b4 it used to have numbers the correspond to the error status which was making sense.
#12118
The text was updated successfully, but these errors were encountered: