Laravel 5.2表单验证不显示错误?

问题描述:

我的表单验证未显示任何错误

My form validation is not showing any error

我的routes.php文件如下:

My routes.php file is as follows:

Route::post('/user/add/form', [
    'uses' => 'AdminController@adduser',
    'as' => 'admin.add.user.to.database' 
    ]); 

我在AdminController中的adduser函数包含以下内容:

My adduser function in AdminController contains following:

$this->validate($request,[
        'email'=> 'required|email',
        'name'=> 'required',
        'password'=> 'required',
        'aright'=> 'required',
        'dob' => 'date',
        'publication'=> 'string',
        'utype' => 'required'
]);

这是我用于表格的刀片视图.这要求一些在控制器功能中显示的字段,如果未填写必填字段但未显示任何内容,则应显示错误.

This is the blade view which I am using for form. This asks for some of the fields whihc are shown in controller function and should show the error if the required field are not filled but it is not showing anything.

@extends('layouts.admin-master')

@section('styles')
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap /3.3.6/css/bootstrap.min.css">
@endsection

@section('scripts')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script type="text/javascript">
    var token = "{{ Session::token() }}";
</script>
@endsection
@section('content')
@include('includes.info')
@if(count($errors) > 0)


        @foreach($errors->all() as $error)
            <h1> {!! $error->first() !!} </h1>
        @endforeach

@endif
<div class="container">
    <h2>Add User Form</h2>
<form  class="form-horizontal" method="post" action="{{ route('admin.add.user.to.database') }}">
    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label col-sm-2" for="email">Email:</label>
              <div class="col-sm-10">
                <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" value="{{ Request::old('email') }}">
              </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label col-sm-2" for="name">Name:</label>
              <div class="col-sm-10">          
                <input type="text" class="form-control" id="name" placeholder="Enter name" name="name">
              </div>
            </div>
        </div>

    </div>

    <div class="row">
        <div class="col-sm-6">    
            <div class="form-group">
              <label class="control-label col-sm-2" for="pwd">Password:</label>
              <div class="col-sm-10">          
                <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password">
              </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="form-group"> 
                <label class="control-label col-sm-2"  for="aright">Access Type:</label>
                    <select class="col-sm-10" id="aright" name="aright">
                        <option value="2">Normal Member</option>
                        <option value="1">Admin</option>
                    </select>
            </div>
        </div>    
    </div>

    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label col-sm-2" for="publication">Publication:</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="publication" placeholder="Enter publication link" name="publication">
              </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label col-sm-2" for="dob">Date of birth:</label>
              <div class="col-sm-10">          
                <input type="date" class="form-control" id="dob" placeholder="Enter DOB" name="dob">
              </div>
            </div>
        </div>

    </div>
    <div class="form-group"> 
                <label class="control-label col-sm-2"  for="utype">User Type:</label>
                    <select class="col-sm-10" id="aright" name="utype">
                        <option value="2">Faculty</option>
                        <option value="1">Student</option>
                    </select>
    </div>
    <div class="form-group text-center">        
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
    </div>
     <input type="hidden" name="_token" value="{{ Session::token() }}">
</form>

</div>

@endsection

自2015年5月25日发布的v5.2.27起,默认情况下,app \ Http \ routes.php中的所有路由现在都位于Web中间件组中.如果您已在app \ Http \ routes.php文件中明确指定此中间件组,则需要将其删除.

As of v5.2.27, released on 2015-03-25, all routes in app\Http\routes.php are now in the web middleware group by default. If you have explicitly specified this middleware group inside your app\Http\routes.php file, you need to remove it.