我有一個 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'); }現(xiàn)在我想創(chuàng)建并驗(yàn)證一張卡: 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' ]);但這是行不通的。當(dāng)我插入某些內(nèi)容(圖像或音頻)時,出現(xiàn)錯誤:The answer field is required when answer image / answer audio is not present.所以 - 我想這是行不通的。還是我錯了?也許我必須使用另一種語法?但我在文檔中沒有找到任何內(nèi)容。請幫忙。
1 回答

qq_遁去的一_1
TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個贊
您已在規(guī)則中添加空格
'answer' => 'required_without: answerImage, answerAudio',
改成這樣
'answer' => 'required_without:answerImage,answerAudio',
和
'question' => 'required_without_all: questionImage, questionAudio',
對此
'question' => 'required_without_all:questionImage,questionAudio',
- 1 回答
- 0 關(guān)注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消