Categories
Mastering Development

Laravel Validation Array must contain one item where boolean is true

I’m validating question and answers (for test creation). I’d like to ensure that the answers array contains at least one ‘correct’ item. So where answers.*.correct => true. I currently have the following: public function rules() { return [ ‘title’ => ‘required|string|max:255’, ‘test_id’ => ‘required|integer|exists:tests,id’, ‘content’ => ‘required’, ‘answers’ => ‘required|array’, ‘answers.*.text’ => ‘required|string|max:255’, ‘answers.*.correct’ => […]