You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.8 KiB

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
class CreateExerciseRequest 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 [
'name' => 'required|string',
'grade_id' => 'required|integer',
'subject_id' => 'required|integer',
'category_id' => 'required|integer',
'skill' => 'required|array',
'level' => 'required|integer',
'groups' => 'required'
];
}
public function messages(): array
{
return [
'name.required' => 'Vui lòng nhập tên bài.',
'grade_id.required' => 'Vui lòng nhập khối lớp.',
'subject_id.required' => 'Vui lòng nhập môn học.',
'category_id.required' => 'Vui lòng nhập danh mục',
'skill.required' => 'Vui lòng nhập tên kĩ năng.',
'level.required' => 'Vui lòng nhập trình độ.',
'groups.required' => 'Vui lòng nhập danh sách các nhóm câu hỏi.'
];
}
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json([
'success' => false,
'message' => 'Dữ liệu không hợp lệ',
'errors' => $validator->errors()
], 422));
}
}