Spaces:
Running
Running
File size: 1,849 Bytes
907b200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <?php
namespace App\Http\Requests\Docking;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class SubmitDockingRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'protein_name' => 'required|string|max:255',
'ligand_name' => 'nullable|string|max:255',
'ligand_file' => 'nullable|file|required_without:ligand_smiles',
'ligand_smiles' => 'nullable|string|max:2000|required_without:ligand_file',
'protein_file' => 'required|file',
'center_x' => 'required|numeric',
'center_y' => 'required|numeric',
'center_z' => 'required|numeric',
'box_size_x' => 'required|numeric',
'box_size_y' => 'required|numeric',
'box_size_z' => 'required|numeric',
'exhaustiveness' => 'nullable|integer',
'n_poses' => 'nullable|integer',
];
}
public function withValidator(Validator $validator): void
{
$validator->after(function (Validator $validator) {
if ($this->hasFile('ligand_file') && $this->filled('ligand_smiles')) {
$validator->errors()->add(
'ligand_input',
'Provide either a ligand file or a SMILES string, not both.'
);
}
});
}
protected function failedValidation(Validator $validator): void
{
throw new HttpResponseException(
response()->json([
'success' => false,
'message' => 'Validation Error',
'data' => ['errors' => $validator->errors()],
], 422)
);
}
}
|