gpt4 book ai didi

php - Laravel Livewire 验证 - required_without_all 和 required_without 不起作用

转载 作者:行者123 更新时间:2023-12-04 09:16:50 30 4
gpt4 key购买 nike

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

最佳答案

您已在规则中添加了空间

'answer' => 'required_without: answerImage, answerAudio',
改成这个
'answer' => 'required_without:answerImage,answerAudio',

'question' => 'required_without_all: questionImage, questionAudio',
对此
'question' => 'required_without_all:questionImage,questionAudio',

关于php - Laravel Livewire 验证 - required_without_all 和 required_without 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63179984/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com