Skip to content

Commit

Permalink
Cathing up with main release ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulhaque committed Oct 23, 2023
1 parent 1b9825f commit 36b73ce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `laravel-filepond` will be documented in this file.

## 0.6.5 - 2023-10-23

- Fixed single file upload as array #47. 🐛
- New test cases added single file upload as array.

## 0.6.4 - 2023-10-12

- Fixed nested validation bug. 🐛
Expand Down
11 changes: 5 additions & 6 deletions src/Services/FilepondService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RahulHaque\Filepond\Services;

use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -31,23 +32,21 @@ public function __construct()
*/
protected function getUploadedFile(Request $request)
{
$input = collect($request->allFiles())->first();
$field = array_key_first(Arr::dot($request->all()));

return is_array($input) ? $input[0] : $input;
return $request->file($field);
}

/**
* Validate the filepond file
*
* @param Request $request
* @param array $rules
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validator(Request $request, array $rules)
{
$field = array_key_first($request->all());
$field = array_key_first(Arr::dot($request->all()));

return Validator::make([$field => $this->getUploadedFile($request)], [$field => $rules]);
return Validator::make($request->all(), [$field => $rules]);
}

/**
Expand Down
25 changes: 24 additions & 1 deletion tests/Unit/FilepondProcessRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function can_validate_filepond_file_upload_request()
'accept' => 'application/json'
]);

$response->assertJson(["avatar" => ["The avatar field is required."]]);
$response->assertJson(["avatar" => ["The avatar must be a file."]]);
}

/** @test */
Expand All @@ -55,4 +55,27 @@ function can_process_filepond_file_upload_request()

Storage::disk(config('filepond.temp_disk', 'local'))->assertExists($fileById->filepath);
}

/** @test */
function can_process_filepond_array_file_upload_request()
{
Storage::disk(config('filepond.temp_disk', 'local'))->deleteDirectory(config('filepond.temp_folder', 'filepond/temp'));

$user = factory(User::class)->create();

$response = $this
->actingAs($user)
->post(route('filepond-process'), [
'gallery' => ['profile' => UploadedFile::fake()->image('avatar.png', 1024, 1024)],
], [
'Content-Type' => 'multipart/form-data',
'accept' => 'application/json',
]);

$data = Crypt::decrypt($response->content(), true);

$fileById = Filepond::find($data['id']);

Storage::disk(config('filepond.temp_disk', 'local'))->assertExists($fileById->filepath);
}
}

0 comments on commit 36b73ce

Please sign in to comment.