Skip to content

Commit

Permalink
📝 updating with example
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Jan 12, 2018
1 parent a39ad62 commit 5b13cbb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add to your project with compoer via `composer require photogabble/laravel-remem

Next add the package service provider to your providers configuration in Laravel.

```
```php
'providers' => [
// ...

Expand All @@ -24,8 +24,24 @@ Now you can assign the middleware `remember.files` to routes that you want the p

To ensure that remembered files remain as such accross 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`.

```
```php
@if( $oldFile = oldFile('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 `oldFile` helper:

```php
function store(Illuminate\Http\Request $request) {
if ($file = oldFile('img', $request->file('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.

This example is viewable as a test case within this libaries tests [here](https://github.com/photogabble/laravel-remember-uploads/blob/master/tests/UploadTest.php#L114).

0 comments on commit 5b13cbb

Please sign in to comment.