Laravel 5验证无效

时间:2015-12-04 20:03:34

标签: php validation laravel-5.1

我的路线代码如下所示

Route::post('doCheckIn', 'TransactionController@store');

我在Controller中的商店看起来像这样,我试图在房间里检查...

public function store(Request $request)
    {

        for ($x=1; $x<=$request->num; $x++)
        {
            if($request->input('guest_name'.$x) == "")
            {
                //echo 'here';
            }
            $this->validate($request, [
            'guest_name'.$x => 'required',
            'room_num'.$x => 'required',
            'check_in'.$x => 'required',
            'check_out'.$x => 'required',
            ]);
        }

正如你所看到的,我的商店功能中有一个if语句,当我注释掉this->validate(...)时,它的效果非常好。它在页面上回响。但是当我摆脱评论并试图验证表格时它不会起作用。这意味着验证功能甚至不起作用。 页面显示

  

MethodNotAllowedHttpException in RouteCollection.php line 219:

我尝试制作另一个Laravel项目并在单独的页面中运行它并且它有效。问题是我的所有代码都在这个项目文件夹中。我卡住了!有人请帮忙。在使用验证之前是否必须使用任何类?

...更新 这是我的表格

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Check In</title>
        <!--CSS And JavaScript -->

    </head>
    <body>

        <h1>Check in</h1>

        </table>
@if (count($errors) > 0)
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
    <form action="doCheckIn" method="POST">
    <tr><td><input type="hidden"  id="num" name="num" value="{{$numroom}}"/></td></tr>
    @for ($x=1;$x<=$numroom; $x++)
    <tr>
        <td>Guest Name:</td>
        <td>
                    <input  type="text" id="guest_name{{$x}}" 
                            name="guest_name{{$x}}"/><div id="guest_namewarn1"></td>
    </tr>
    <tr>
        <td>Room Number:</td>
        <td><input type="text"  id="room_num{{$x}}"   
                           name="room_num{{$x}}" size="5" maxlength="4"/></td>
    </tr>
    <tr>
        <td>Check In:</td>
        <td><input type="date"  id="check_in{{$x}}" value="2015-12-04" name="check_in{{$x}}"/></div></td>

    </tr>
    <tr>
        <td>Check out:</td>
                <td><input type="date"  id="check_out{{$x}}"  name="check_out{{$x}}"/><br><br></td>

    </tr>
    @endfor
        {{csrf_field()}}
    <tr><td>
                <input type="submit" id="s_button" value="Check in" ><br><br><button type="button" name="back" onclick="goBack()">Kembali</button>
        </td></tr>

    </form>



    </body>
</html>

0 个答案:

没有答案