2

I have a livewire component:

  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');
   }

Now I want to create and validate a card:

   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'
    ]);

But this is not working. When I insert something (image or audio) I get the error:

The answer field is required when answer image / answer audio is not present.

So - I guess this is not working. Or am I wrong? Maybe I have to use another syntax? But I found nothing in the docs.

Please help.

1 Answer 1

2

You have added space in the rule

'answer' => 'required_without: answerImage, answerAudio',

Change it to this

'answer' => 'required_without:answerImage,answerAudio',

And

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

to this

'question' => 'required_without_all:questionImage,questionAudio',
Sign up to request clarification or add additional context in comments.

1 Comment

Yes - that was it. Thanks very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.