laravel抛出MethodNotAllowedHttpException进行验证

时间:2019-03-07 19:26:33

标签: php laravel

我试图用post方法创建一个表单。当该方法中存在验证时,我遇到了“ Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException”,但是当我删除验证时,它可以正常工作。我不知道为什么!

HTML

@if(count($errors)>0)
    <ul>
        @foreach($errors->all() as $error)
            <li style="color: #cc5200;"><i class="fas fa-times"></i>{{$error}}</li>
        @endforeach
    </ul>
@endif
    <form method="post" action="{{route('test.added')}}">
        @csrf
        <input type="hidden" name="grade" value="{{$grade}}">
        <input type="hidden" name="course" value="{{$course}}">
        <input type="hidden" name="numbers" value="{{$numbers}}">
        @for($i=0;$i<$numbers;$i++)
            <div>
                <span style="color: #cc5200">question{{$i+1}} :</span>
                <textarea name="question[]" rows="2" style="width: 50vw">{{old('question')[$i]}}</textarea>
            </div>
            <div class="d-flex flex-row">
                <div class="ml-1 mr-2">
                    <span>1-</span>
                    <input type="text" name="firstOption[]" style="width: 10vw" value="{{old('firstOption')[$i]}}">
                    <input type="radio" name="trueOption[{{$i}}]" value="1">
                </div>
                <div class="ml-1 mr-2">
                    <span>2-</span>
                    <input type="text" name="secondOption[]" style="width: 10vw" value="{{old('secondOption')[$i]}}">
                    <input type="radio" name="trueOption[{{$i}}]" value="2">
                </div>
                <div class="ml-1 mr-2">
                    <span>3-</span>
                    <input type="text" name="thirdOption[]" style="width: 10vw" value="{{old('thirdOption')[$i]}}">
                    <input type="radio" name="trueOption[{{$i}}]" value="3">
                </div>
                <div class="ml-1 mr-2">
                    <span>4-</span>
                    <input type="text" name="forthOption[]" style="width: 10vw" value="{{old('forthOption')[$i]}}">
                    <input type="radio" name="trueOption[{{$i}}]" value="4">
                </div>
            </div>
            <br>
        @endfor
        <input type="submit" value="ok" style="float: left;color: white;background: #cc5200">
    </form>

web.php

Route :: post('/ td-admin / test / add-finalStage','TestController @ added')-> name('test.added');

TestController

public function added(Request $request){

    $request->validate([
        'question.*'=>'required',
        'firstOption.*'=>'required',
        'secondOption.*'=>'required',
        'thirdOption.*'=>'required',
        'forthOption.*'=>'required',
        'trueOption.*'=>'required',
    ]);
    Test::create(  ...

这让我发疯了。请帮助我。

0 个答案:

没有答案