2017 © Pedro Peláez
 

library laravel-remember-uploads

Laravel middleware and helper for remembering uploaded files during form validation.

image

photogabble/laravel-remember-uploads

Laravel middleware and helper for remembering uploaded files during form validation.

  • Wednesday, March 14, 2018
  • by carbontwelve
  • Repository
  • 2 Watchers
  • 58 Stars
  • 55 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 4 % Grown

The README.md

Laravel Remember Uploads

Middleware Package, (*1)

Build Status Latest Stable Version License , (*2)

About this package

This middleware solves the issue of unrelated form validation errors redirecting the user back and loosing the files that had been uploaded. It does this by temporarily caching server-side the file fields that have passed validation so that they may be processed once the whole form has been submitted passing validation., (*3)

Install

Add to your project with composer via composer require photogabble/laravel-remember-uploads., (*4)

Laravel Version >= 5.5

This library supports package auto-discovery in Laravel >= 5.5., (*5)

Laravel Versions 5.2 - 5.5

To enable the package you will need to add its service provider to your app providers configuration in Laravel., (*6)

'providers' => [
    // ...

    Photogabble\LaravelRememberUploads\RememberUploadsServiceProvider::class,

    // ...
],

Usage

You need to assign the middleware remember.files to routes that process uploaded files; in the case of CRUD terminology that would be the create and update methods., (*7)

So that the middleware is aware of remembered files from the previous request you need to include a reference by way of using a hidden input field with the name _rememberedFiles., (*8)

@if( $oldFile = rememberedFile('file'))
    <input type="hidden" name="_rememberedFiles[file]" value="{{ $oldFile->getFilename() }}">
@else
    <input type="file" name="file">
@endif

Then within your controller code you can obtain the file via the rememberedFile helper:, (*9)

function store(Illuminate\Http\Request $request) {    
    if ($file = $request->file('img', rememberedFile('img')) {
        // ... File exists ...
    }
}

The $file variable will equal an instance of Symfony\Component\HttpFoundation\File\UploadedFile if the file has been posted during the current request or remembered., (*10)

This example is viewable as a test case within this libaries tests., (*11)

Array File Fields

In the case where you have multiple upload fields sharing the same name for example image[0], image[1]; the helper rememberedFile('image') will return an array of Symfony\Component\HttpFoundation\File\UploadedFile., (*12)

The reference _rememberedFiles will also need to match the array syntax of the file inputs it mirrors:, (*13)

@if( $oldFile = rememberedFile('image'))
    <!-- $oldFile is now an array of Symfony\Component\HttpFoundation\File\UploadedFile -->
    <input type="hidden" name="_rememberedFiles[image][0]" value="{{ $oldFile[0]->getFilename() }}">
    <input type="hidden" name="_rememberedFiles[image][1]" value="{{ $oldFile[1]->getFilename() }}">
@else
    <input type="file" name="image[0]">
    <input type="file" name="image[1]">
@endif

The Versions

14/03 2018

dev-master

9999999-dev

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

14/03 2018

1.3.0

1.3.0.0

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

14/03 2018

dev-1.3.0-dev

dev-1.3.0-dev

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

03/03 2018

dev-1.3.0dev-issue15

dev-1.3.0dev-issue15

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

21/02 2018

1.3.0-alpha

1.3.0.0-alpha

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

19/01 2018

dev-issue12-add-travis-ci

dev-issue12-add-travis-ci

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

19/01 2018

dev-issue10-supportautodiscovery

dev-issue10-supportautodiscovery

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

16/01 2018

1.2.0

1.2.0.0

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

16/01 2018

dev-issue6

dev-issue6

Laravel middleware and helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel middleware file validation

12/01 2018

1.1.0

1.1.0.0

A simple helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel file validation

25/10 2017

1.0.0

1.0.0.0

A simple helper for remembering uploaded files during form validation.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel file validation