猿问

Laravel Livewire 验证 - required_without_all

我有一个 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.

所以 - 我想这是行不通的。还是我错了?也许我必须使用另一种语法?但我在文档中没有找到任何内容。


请帮忙。


白衣非少年
浏览 78回答 1
1回答

qq_遁去的一_1

您已在规则中添加空格'answer' => 'required_without: answerImage, answerAudio',改成这样'answer' => 'required_without:answerImage,answerAudio',和'question' => 'required_without_all: questionImage, questionAudio',对此'question' => 'required_without_all:questionImage,questionAudio',
随时随地看视频慕课网APP
我要回答