我有一个 Livewire 组件: class Cards extends Component { use WithFileUploads; public $question; public $answer; public $questionImage; public $questionImageOrigin; public $answerImage; public $answerImageOrigin; public $questionAudio; public $questionAudioOrigin; public $answerAudio; public $answerAudioOrigin; public function render() { return view('livewire.cards'); }现在我想创建并验证一张卡: public function createCard(){ $this->validate([ 'answerImage' => 'nullable|image|max:3000', 'questionImage' => 'nullable|image|max:3000', 'question' => 'required_without_all: questionImage, questionAudio', 'answer' => 'required_without: answerImage, answerAudio', 'questionAudio' => 'nullable|file|mimeTypes:audio/mpeg|max:3000', 'answerAudio' => 'nullable|file|mimeTypes:audio/mpeg|max:3000' ]);但这是行不通的。当我插入某些内容(图像或音频)时,出现错误:The answer field is required when answer image / answer audio is not present.所以 - 我想这是行不通的。还是我错了?也许我必须使用另一种语法?但我在文档中没有找到任何内容。请帮忙。
1 回答
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
您已在规则中添加空格
'answer' => 'required_without: answerImage, answerAudio',
改成这样
'answer' => 'required_without:answerImage,answerAudio',
和
'question' => 'required_without_all: questionImage, questionAudio',
对此
'question' => 'required_without_all:questionImage,questionAudio',
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报
0/150
提交
取消