Skip to content

Proposal for revision #41

@aeremichev

Description

@aeremichev

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions