-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60d1286
commit 4631253
Showing
4 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Support\Arr; | ||
|
||
class Dropzone | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (($request->method() != 'POST') && ($request->method() != 'PATCH')) { | ||
return $next($request); | ||
} | ||
|
||
$multiple = false; | ||
|
||
foreach ($request->all() as $key => $value) { | ||
if (!is_array($value)) { | ||
continue; | ||
} | ||
|
||
$files = []; | ||
$uploaded = []; | ||
|
||
foreach ($value as $index => $parameter) { | ||
// single file uploaded.. | ||
if (!is_array($parameter) && !$multiple) { | ||
if (!Arr::has($value, 'dropzone')) { | ||
continue; | ||
} | ||
|
||
$request->request->set('uploaded_' . $key, $value); | ||
|
||
unset($request[$key]); | ||
break; | ||
} | ||
|
||
// multiple file uploaded.. | ||
if (!Arr::has($parameter, 'dropzone')) { | ||
$files[] = $parameter; | ||
|
||
continue; | ||
} | ||
|
||
$multiple = true; | ||
$uploaded[] = $parameter; | ||
} | ||
|
||
if ($multiple && $uploaded) { | ||
$request->request->set('uploaded_' . $key, $uploaded); | ||
$request->request->set($key, $files); | ||
} | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters