Skip to content

Commit 28d0667

Browse files
authored
🔖 1.3.0 release (#20)
* ✨ 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
1 parent 0f927f6 commit 28d0667

15 files changed

+588
-3263
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
vendor
2+
vendor
3+
composer.lock

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
<p align="center"><em>Middleware Package</em></p>
33

44
<p align="center">
5+
<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>
56
<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>
67
<a href="LICENSE"><img src="https://img.shields.io/github/license/photogabble/laravel-remember-uploads.svg" alt="License"></a>
78
</p>
89

910
## About this package
1011

11-
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.
12+
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.
1213

1314
## Install
1415

1516
Add to your project with composer via `composer require photogabble/laravel-remember-uploads`.
1617

18+
### Laravel Version >= 5.5
19+
20+
This library supports [package auto-discovery](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518) in Laravel >= 5.5.
21+
22+
### Laravel Versions 5.2 - 5.5
23+
1724
To enable the package you will need to add its service provider to your app providers configuration in Laravel.
1825

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

29-
Now you can assign the middleware `remember.files` to routes that you want the packages functionality to operate on.
30-
3136
## Usage
3237

33-
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`.
38+
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.
39+
40+
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`.
3441

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

5360
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.
5461

55-
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).
62+
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).
63+
64+
### Array File Fields
65+
66+
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`.
67+
68+
The reference `_rememberedFiles` will also need to match the array syntax of the file inputs it mirrors:
69+
70+
```php
71+
@if( $oldFile = rememberedFile('image'))
72+
<!-- $oldFile is now an array of Symfony\Component\HttpFoundation\File\UploadedFile -->
73+
<input type="hidden" name="_rememberedFiles[image][0]" value="{{ $oldFile[0]->getFilename() }}">
74+
<input type="hidden" name="_rememberedFiles[image][1]" value="{{ $oldFile[1]->getFilename() }}">
75+
@else
76+
<input type="file" name="image[0]">
77+
<input type="file" name="image[1]">
78+
@endif
79+
```

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "5.7.*",
28-
"orchestra/testbench": "~3.0"
28+
"orchestra/testbench": "~3.4"
2929
},
3030
"autoload": {
3131
"psr-4": {
@@ -43,6 +43,11 @@
4343
"extra": {
4444
"branch-alias": {
4545
"dev-master": "1.3.0-dev"
46+
},
47+
"laravel": {
48+
"providers": [
49+
"Photogabble\\LaravelRememberUploads\\RememberUploadsServiceProvider"
50+
]
4651
}
4752
}
4853
}

0 commit comments

Comments
 (0)