Support the ongoing development of Laravel.io →
Eloquent Forms Validation

I am trying to seed an image, however it fails a validator test for 'image' - even though I am passing it an instance of Symfony\Component\HttpFoundation\File\UploadedFile - can anyone explain why, and what type of object it expects to receive?

My validator is as follows: 'logo' => 'image'

And I am seeding it by doing this:

$input['logo'] contains the filname of the logo e.g. 14853.jpg

$input['logo'] = new UploadedFile(DIR.'/installers/'.$input['logo'], $input['logo'], 'image/jpeg');

Many thanks

agjmills

Last updated 3 years ago.
0

It wont pass the validator unless you pass the filesize of the file you are "uploading" into the constructor of the Symfony\Component\HttpFoundation\UploadedFile class

However now the error that is received is: The file "18233.jpg" was not uploaded due to an unknown error.

Last updated 3 years ago.
0

You can't just instantiate the UploadedFile class like that. Part of the validation will check whether the file is actually an uploaded file using is_uploaded_file. However, whilst the validator requires an instance of File, it uses methods only available on the UploadedFile class.

So essentially there's a bug in the validator, which will stop you manually init'ing a File class and using it with image validation (i've submitted a pull request with a fix, but with 100+ other active PR's, might be a while until Taylor gets around to checking it out and either accepting it, or telling me he doesn't like the fix).

In the meantime, you have the usual options. You can wait, you can maintain your own fixed fork for a while, you can remove the validation, or create a custom image validator rather than using the inbuilt one.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

agjmills agjmills Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.