mardi 30 janvier 2018

how to validate unique composite key of array data for update in laravel 5.5

Input data:

{
    "exam_scores": [
        {
            "id": 19,
            "student_id": 1,
            "marks": 89,
            "remarks": "Good"
        },
        {
            "id": 20,
            "student_id": 2,
            "marks": 95,
            "remarks": "Excellent"
        }
    ],
    "exam_id": 10
}

My validation for update:

return [
 'exam_scores.*.student_id'=> "distinct|unique:exam_scores,student_id,exam_scores.*.id,id,exam_id,".$this->exam_id]
]

Question: How to make "exam_scores.*.id" field dynamic. Meaning it should correlate with each record of array.

Note: The following validation rule for store is working as expected.

'exam_scores.*.student_id'=> "distinct|unique:exam_scores,student_id,null,exam_scores,exam_id,".$this->exam_id



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire