CRUD
CRUD copied to clipboard
[Bug] ValidUpload performs no validation during request validation when upload field is used as subfield
Bug report
What I did
Defined a relationship within the model:
public function entities(): HasMany
{
return $this->hasMany(Entity::class);
}
Defined a relationship field including an upload field as subfield:
[
'name' => 'entities',
'label' => __('Some Entities'),
'type' => 'relationship',
'subfields' => [
[
'name' => 'document',
'label' => __('Document'),
'type' => 'upload',
'withFiles' => [
'disk' => 's3',
'path' => 'upload',
],
],
]
],
Defined validation rules within Request:
'entities.*.document' => ValidUpload::field('required')->file('mimes:pdf,jpeg,png,jpg,gif,svg|max:20480'),
What I expected to happen
- Field is marked as required (Asterisk *) in UI.
- Field will be validated for required/actual file provided on submit.
- Uploaded file will be validated against required mime types and size.
What happened
- Field is marked as required in UI (Asterisk *). ✅
- Field will be validated for required/actual file provided on submit. ❌
- Uploaded file will be validated against required mime types and size. ❌
I am able to save empty files or files which do not match the mime type. Therefore it looks like no validation at all is performed.
What I've already tried to fix it
When I use the same configuration as a root element without subfield or relationship the validation works properly.
Is it a bug in the latest version of Backpack?
yes
Backpack, Laravel, PHP, DB version
PHP VERSION:
PHP 8.2.12 (cli) (built: Oct 26 2023 17:33:49) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.12, Copyright (c) Zend Technologies with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
LARAVEL VERSION:
10.38.1.0
BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.2.2 backpack/crud: 6.4.2 backpack/devtools: 2.0.3 backpack/generators: v4.0.2 backpack/permissionmanager: 7.1.1 backpack/pro: 2.0.20 backpack/revise-operation: 2.0.0 backpack/theme-tabler: 1.1.2
I also checked the actual rules when dumping it in the request... it all looks properly setup and configured. I got no idea. Is it maybe related to the issue I reported regarding validation and behaviour of upload_multiple a few weeks ago?
Sorry for opening the third issue. But I try a lot of ways and invest 1-3 hours before opening a bug report here.
Hi @daPhantom,
Thanks for reporting the issue, and don't worry about posting many issues. As long as you spend time validating the scenarios and think something is not working properly, we appreciate you taking the time to post it here. If this is a valid issue, everyone will get the benefit.
I will try to reproduce this and assign it to the team if this is indeed an issue. In any way, we will keep you posted.
Thanks!
related with #5440