first
This commit is contained in:
52
app/Http/Requests/User/CreateProjectRequest.php
Normal file
52
app/Http/Requests/User/CreateProjectRequest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\User;
|
||||
|
||||
use App\Rules\ValidAudioMagicBytes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateProjectRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->isActive();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$maxKb = config('speech2text.upload.max_mb', 200) * 1024;
|
||||
$extensions = implode(',', config('speech2text.upload.allowed_extensions'));
|
||||
|
||||
return [
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'audio' => [
|
||||
'required',
|
||||
'file',
|
||||
"mimes:{$extensions}",
|
||||
"max:{$maxKb}",
|
||||
new ValidAudioMagicBytes(),
|
||||
],
|
||||
'language' => ['nullable', 'string', 'in:ms,en'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Tajuk projek',
|
||||
'description' => 'Penerangan',
|
||||
'audio' => 'Fail audio',
|
||||
'language' => 'Bahasa',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
$maxMb = config('speech2text.upload.max_mb', 200);
|
||||
return [
|
||||
'audio.max' => "Saiz fail audio melebihi had maksimum {$maxMb}MB.",
|
||||
'audio.mimes' => 'Format fail tidak disokong. Guna: mp3, wav, m4a, mp4, aac, ogg, flac, webm.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user