ldc-com-app-bo/app/Http/Requests/Bo/ImportRequest.php

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2023-03-31 15:24:32 +02:00
<?php
namespace App\Http\Requests\Bo;
use Illuminate\Foundation\Http\FormRequest;
class ImportRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
2023-03-31 15:24:32 +02:00
{
2023-07-13 08:34:54 +00:00
return auth('backend')->check();
2023-03-31 15:24:32 +02:00
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
2023-03-31 15:24:32 +02:00
{
return [
'import' => [
'required',
'file',
'mimes:csv,txt',
// phpcs:ignore Generic.Files.LineLength.TooLong
'mimetypes:text/csv,text/plain,application/csv,text/comma-separated-values,text/anytext,application/octet-stream,application/txt',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
2023-03-31 15:24:32 +02:00
function ($attribute, $value, $fail) {
if (
$this->import->getClientMimeType() !== 'text/csv'
&& $this->import->getClientMimeType() !== 'application/vnd.ms-excel'
) {
$fail(__('Le fichier doit être d\'un mime type text/csv ou application/vnd.ms-excel'));
}
}
]
];
}
}