我有一个 Laravel Livewire 组件,其中包含一个 Blade 组件,就像这样
<div>
<div class="card-header">
<div>{{ $quiz->name }}</div>
<x-create-question-modal :state="$modalQuestionState" :question="$question"/>
</div>
@foreach($quiz->questions as $question)
<div class="card-body">
<div class="card-title">
{{ $question->question }}
</div>
@foreach($question->choices as $choice)
<div class="card-text">
{{ $choice->name }}
</div>
@endforeach
</div>
<hr>
@endforeach
</div>
这是我的刀片组件
<div>
<div>
<div wire:click="modalCreateQuestionToggle">Create New Quiz</div>
</div>
{{-- Create Quiz Modal --}}
<div class="modal @if($state) d-block @endif" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Create New Quiz</h5>
<button wire:click="modalCreateQuestionToggle" type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form wire:submit.prevent="store">
<div class="modal-body">
<input type="text" wire:model="question">
@error('question') <span class="error alert-danger">{{ $message }}</span> @enderror
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
</div>
</div>
</div>
</div>
这是store
我在Livewire
课堂上的方法,
public function store() {
//
$this->validate([
'question' => 'required|min:5',
]);
Questions::create([
'question' => $this->question,
'quiz_id' => $this->quiz->id
]);
$this->modalQuestionState = !$this->modalQuestionState;
$this->question = null;
}
调用商店时,验证失败,但由于某种原因,它没有在我的刀片组件中呈现。
这是livewire网络的输出
errorBag: {question: ["The question must be at least 5 characters."]}
question: ["The question must be at least 5 characters."]