Skip to content

Commit

Permalink
🔖 1.3.0 release (#20)
Browse files Browse the repository at this point in the history
* ✨ Support Auto-Discovery #10 (#11)

* 📝 add build status

* Fixes #15 (#18)

* Failing test written as confirmation of issue #15

* added remembered file entity

* construct from and export to UploadedFile

* Compose with RememberedFile instead of array

* Use Illuminate UploadedFile, this is for Laravel after all

* working towards solving #15

* Memo to self

* notes

* Made much more DRY

* Wrote testArrayFileUploadOldRemembered test

* Added RememberedFileBag

* Refactored to add functionality for issue #15

* Removed final inspection warning

* Added failing test for checking validation errors invalidate array uploads

* Update to support laravel 5.4 as a minimum

* Fix unit test

* Remove composer.lock this is a lib not a project

* Replace Illuminate UploadedFile with Symfony UploadedFile

* Test able to reproduce bug discovered by Jarosław Goszowski on issue #15

* Fixed

* Amended documentation for #17

* Added configuration as per #16
  • Loading branch information
carbontwelve authored Mar 14, 2018
1 parent 0f927f6 commit 28d0667
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 3,263 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
vendor
vendor
composer.lock
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
<p align="center"><em>Middleware Package</em></p>

<p align="center">
<a href="https://travis-ci.org/photogabble/laravel-remember-uploads"><img src="https://travis-ci.org/photogabble/laravel-remember-uploads.svg?branch=master" alt="Build Status"></a>
<a href="https://packagist.org/packages/photogabble/laravel-remember-uploads"><img src="https://img.shields.io/packagist/v/photogabble/laravel-remember-uploads.svg" alt="Latest Stable Version"></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/photogabble/laravel-remember-uploads.svg" alt="License"></a>
</p>

## About this package

This middleware allows the application to capture uploaded files and temporarily store them just-in-case the form validation redirects back otherwise losing the files before your controller could process them.
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](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518) 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.

```php
Expand All @@ -26,11 +33,11 @@ To enable the package you will need to add its service provider to your app prov
],
```

Now you can assign the middleware `remember.files` to routes that you want the packages functionality to operate on.

## Usage

To ensure that remembered files remain as such across page refreshes (due to other validation errors) you need to include a reference by way of using a hidden input field with the name `_rememberedFiles`.
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`.

```php
@if( $oldFile = rememberedFile('file'))
Expand All @@ -52,4 +59,21 @@ function store(Illuminate\Http\Request $request) {

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](https://github.com/photogabble/laravel-remember-uploads/blob/master/tests/UploadTest.php#L114).
This example is viewable as a test case [within this libaries tests](https://github.com/photogabble/laravel-remember-uploads/blob/master/tests/UploadTest.php#L192).

### 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:

```php
@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
```
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"phpunit/phpunit": "5.7.*",
"orchestra/testbench": "~3.0"
"orchestra/testbench": "~3.4"
},
"autoload": {
"psr-4": {
Expand All @@ -43,6 +43,11 @@
"extra": {
"branch-alias": {
"dev-master": "1.3.0-dev"
},
"laravel": {
"providers": [
"Photogabble\\LaravelRememberUploads\\RememberUploadsServiceProvider"
]
}
}
}
Loading

0 comments on commit 28d0667

Please sign in to comment.