Skip to content
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

Proposal for revision #41

Open
aeremichev opened this issue Oct 17, 2019 · 0 comments
Open

Proposal for revision #41

aeremichev opened this issue Oct 17, 2019 · 0 comments

Comments

@aeremichev
Copy link

Hi, Mohd Saqueib Ansari!

Thank you very much for developing this package.

I have a suggestion for revision.
In the example, you describe a use case
 $ user->update ($request->all());

But I often have a need to pass $ request->book parameters to the update method where the information about the file to be downloaded is kept, for example $request->book->cover
 $book->update ($request->book);

But the autoUpload method cannot automatically download this file, because it checks the existence of the file so

 if (request () -> hasFile ($ requestFileName)) {
                $ this-> uploadImage (
                    request () -> file ($ requestFileName),
                    $ field
                );
            }

I have a suggestion to replace this part of the code, so

if (! empty ($ this-> attributes [$ requestFileName]) and $ this-> attributes [$ requestFileName] instanceof UploadedFile) {
                $ this-> uploadImage (
                    $ this-> attributes [$ requestFileName],
                    $ field
                );
            }

As a result, the function will look like this

protected function autoUpload()
    {
        foreach ($this->getDefinedUploadFields() as $key => $val) {
            $field = is_int($key) ? $val : $key;
            $options = Arr::wrap($val);

            // check if global upload is allowed, then in override in option
            $autoUploadAllowed = Arr::get($options, 'auto_upload', $this->canAutoUploadImages());

            if (!$autoUploadAllowed) {
                continue;
            }

            // get the input file name
            $requestFileName = Arr::get($options, 'file_input', $field);

            if (!empty($this->attributes[$requestFileName]) and $this->attributes[$requestFileName] instanceof UploadedFile) {
                $this->uploadImage(
                    $this->attributes[$requestFileName],
                    $field
                );
            }
        }
    }

Do you understand my point?
Can you include this change in the release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant