Download the PHP package photogabble/laravel-remember-uploads without Composer
On this page you can find all versions of the php package photogabble/laravel-remember-uploads. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download photogabble/laravel-remember-uploads
More information about photogabble/laravel-remember-uploads
Files in photogabble/laravel-remember-uploads
Package laravel-remember-uploads
Short Description Laravel middleware and helper for remembering uploaded files during form validation.
License MIT
Informations about the package laravel-remember-uploads
Laravel Remember Uploads
Middleware Package
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.
Install
Add to your project with composer via composer require photogabble/laravel-remember-uploads
.
Laravel Version >= 5.5
This library supports package auto-discovery in Laravel >= 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.
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.
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
.
Then within your controller code you can obtain the file via the rememberedFile
helper:
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.
This example is viewable as a test case within this libaries tests.
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
.
The reference _rememberedFiles
will also need to match the array syntax of the file inputs it mirrors: