41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Modules\Import\Requests;
|
||
|
|
|
||
|
|
use Closure;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Http\UploadedFile;
|
||
|
|
|
||
|
|
class ClientImportRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
// Validate by extension only — Windows CSV exports arrive with a
|
||
|
|
// variety of MIME types (text/plain, application/vnd.ms-excel), so a
|
||
|
|
// strict `mimes:csv` rule would reject legitimate files.
|
||
|
|
'file' => [
|
||
|
|
'required',
|
||
|
|
'file',
|
||
|
|
'max:10240',
|
||
|
|
function (string $attribute, mixed $value, Closure $fail): void {
|
||
|
|
$ext = $value instanceof UploadedFile
|
||
|
|
? strtolower($value->getClientOriginalExtension())
|
||
|
|
: '';
|
||
|
|
if (! in_array($ext, ['csv', 'txt'], true)) {
|
||
|
|
$fail('Bitte eine CSV-Datei (.csv oder .txt) hochladen.');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|