samedi 9 février 2019

Laravel function hasFile() gives error and is not calling InteractsWithInput

Laravel 5.6, Trying to upload files in a Form and I receive error:

Call to a member function hasFile() on array

At this moment I checked:

  • The form has files = true

Form -> {!! Form::open(array('action' => 'PController@store', 'files'=>true

  • The code to add photos support multiple files and has array support (photos[]) on its name:

                    <div class="form-group">
                        <label for="photos" class="control-label">Choose Photo:</label>
                        <input type="file" id="photos" name="photos[]" multiple />
                    </div>
    
    
  • In order to use hasFile i use use Illuminate\Http\Request;

    use Illuminate\Http\Request;

The only remaining thing i found checking similar working code its that hasFile invokes:

vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithInput.php

/**
 * Determine if the uploaded data contains a file.
 *
 * @param  string  $key
 * @return bool
 */
public function hasFile($key)
{
    if (! is_array($files = $this->file($key))) {
        $files = [$files];
    }

    foreach ($files as $file) {
        if ($this->isValidFile($file)) {
            return true;
        }
    }

    return false;
}

and In my case its not calling it. If I checked if it has an implementation in phpstorm software, nothing happens.

I dont know if its that Im not invoking InteractWithInput properly, or if its that the file is not taking into consideration 'files'=>true

any help appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire