45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\AuditionedEnsemble;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class EtudeUploadRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
|
|
return [
|
|
'auditioned_ensemble_id' => ['required', 'exists:auditioned_ensembles,id'],
|
|
'instrument_id' => ['required', 'exists:instruments,id'],
|
|
'set' => [
|
|
'required',
|
|
'numeric',
|
|
'min:1',
|
|
function ($attribute, $value, $fail) {
|
|
/** @noinspection PhpUndefinedFieldInspection */
|
|
$ensemble = AuditionedEnsemble::find($this->audtioned_ensemble_id);
|
|
if ($ensemble && $value > $ensemble->set_count) {
|
|
$fail("The set number cannot exceed {$ensemble->set_count} for this ensemble.");
|
|
}
|
|
},
|
|
],
|
|
'file_upload' => ['required', 'file', 'mimes:pdf', 'mimetypes:application/pdf', 'max:51200'],
|
|
];
|
|
}
|
|
}
|