我有一个 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.
所以 - 我想这是行不通的。还是我错了?也许我必须使用另一种语法?但我在文档中没有找到任何内容。
请帮忙。
qq_遁去的一_1