Php 没有出现拉维误差

Php 没有出现拉维误差,php,laravel,laravel-4,Php,Laravel,Laravel 4,我试图向数据库中添加新的匹配项,但如果我故意不在表单中输入任何内容,则不会显示任何错误。我是根据我的登记表写的,这张表很好用。如果我正确填写表格,所有数据都会正确地进入数据库 MatchController.php public function postCreate() { $validator = Validator::make(Input::all(), Match::$rules); if ($validator->passes()) {

我试图向数据库中添加新的匹配项,但如果我故意不在表单中输入任何内容,则不会显示任何错误。我是根据我的登记表写的,这张表很好用。如果我正确填写表格,所有数据都会正确地进入数据库

MatchController.php

public function postCreate()
{

    $validator = Validator::make(Input::all(), Match::$rules);

    if ($validator->passes()) 
    {

        $datetime = Input::get('year')."-".Input::get('month')."-".Input::get('day')." ".Input::get('time').":00";

        $match = new Match;
        $match->type = Input::get('match_type');
        $match->associate = Input::get('associate');
        $match->date = $datetime;
        $match->location = Input::get('location');
        $match->save();

        $matchp1 = new Matchplayer;
        $matchp1->user_id = Input::get('id');
        $matchp1->match_id = $match->id;
        $matchp1->team = 1;
        $matchp1->save();

        $matchp2 = new Matchplayer;
        $matchp2->user_id = Input::get('opponent');
        $matchp2->match_id = $match->id;
        $matchp2->team = 2;
        $matchp2->save();

        return Redirect::to('members/matches/create')->with('message', 'Match created!');

    }else{
        return Redirect::to('members/matches/create')->withErrors($validator)->withInput();
    }
}
Route::post('members/matches/create', 'MatchController@postCreate');
匹配模型(Match.php) 匹配创建视图(matchCreate.php)

<div class="row clearfix">
        <!-- Error Message Box -->
            @if(Session::has('message'))
            <div class="col-md-8 col-md-offset-2">
                <div class="alert alert-info">{{ Session::get('message') }}</div>
            </div>
            @endif
        <div class="col-md-9">
            <!-- Top Menu BEGIN -->
            <ul class="nav nav-pills nav-justified">
                <li>{{ HTML::link('members/logout', 'Profiles') }}</li>
                <li>{{ HTML::link('members/logout', 'Leagues') }}</li>
                <li class="active">{{ HTML::link('members/logout', 'Add Match') }}</li>
                <li>{{ HTML::link('members/logout', 'Results &amp; Fixtures') }}</li>
                <li>{{ HTML::link('members/logout', 'Matchboard') }}</li>
            </ul>
            <!-- Top Menu END -->
            <div class="page-header">
                <h3>Create a Match</h3>
            </div>
            <div class="col-sm-6">
                {{ Form::open(array('url'=>'members/matches/create', 'action' => 'post', 'class'=>'form-horizontal')) }}
                {{ form::hidden('id', Auth::user()->id) }}
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Match Type</label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ $errors->first('match_type', '<span class="help-block">:message</span>') }}
                        {{ Form::select('match_type', array('singles' => 'Singles', 'doubles' => 'Doubles'), 'singles', array('id' => 'match_type', 'class' => 'form-control input')) }}
                    </div>
                </div>
                <div class="form-group">
                    <label for="gender" class="col-sm-5 control-label col-sm-pad">League Associate</label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ $errors->first('associate', '<span class="help-block">:message</span>') }}
                        {{ Form::text('associate', Input::old('associate'), array('class' => 'form-control input')) }}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Team Mate #1<br><small></small></label>
                    <div class="col-sm-7 col-sm-pad">
                        <p class="form-control-static">{{ Auth::user()->first_name." ".Auth::user()->last_name }}</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Opponent #1</label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ $errors->first('opponent', '<span class="help-block">:message</span>') }}
                        {{ Form::select('opponent', $users, 'key', array('class' => 'form-control input')) }}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Team Mate #2<br><small>(Doubles Only)</small></label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ $errors->first('team_mate2', '<span class="help-block">:message</span>') }}
                        {{ Form::select('team_mate2', $users, 'key', array('class' => 'form-control input')); }}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Opponent #2<br><small>(Doubles Only)</small></label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ $errors->first('opponent2', '<span class="help-block">:message</span>') }}
                        {{ Form::select('opponent2', $users, 'key', array('class' => 'form-control input')) }}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Date</label>
                        {{ $errors->first('day', '<span class="help-block">:message</span>') }}
                        <div class="col-lg-2 col-sm-pad">
                            {{ Form::selectRange('day', 1, 31, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
                        </div>
                        <div class="col-lg-2 col-sm-pad">
                            {{ Form::selectRange('month', 1, 12, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
                        </div>
                        <div class="col-lg-3 col-sm-pad">
                            {{ Form::selectRange('year', 2014, 2015, 'a', array('class' => 'form-control input-sm input dob-form-control')) }}
                        </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Time</label>
                    <div class="col-lg-3 col-sm-pad">
                        {{ $errors->first('time', '<span class="help-block">:message</span>') }}
                        {{ Form::select('time', $times, 'key', array('class' => 'form-control input input-sm dob-form-control')) }}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-5 control-label col-sm-pad">Location</label>
                    <div class="col-sm-7 col-sm-pad">
                        {{ Form::text('location', Input::old('location'), array('class' => 'form-control input')) }}
                    </div>
                </div>
                {{ Form::submit('Create', array('class'=>'btn btn-success btn-block')) }}
                {{ Form::token() . Form::close() }}
            </div>
            <div class="col-sm-6">
            </div>
        </div>
        @include('includes.sidemenu')
    </div>

您正在错误地创建
验证程序
对象。
make()
方法有四个参数:

/**
 * Create a new Validator instance.
 *
 * @param  array  $data
 * @param  array  $rules
 * @param  array  $messages
 * @return \Illuminate\Validation\Validator
 */
public function make(array $data, array $rules, array $messages = array(), array $customAttributes = array()) { ... }

您将每个验证规则作为一个单独的数组传递,而不是作为一个数组一起传递。随后,您也没有传递任何输入数据,因此它没有实际数据可供验证。

您是否检查了应用程序/存储的权限?我的应用程序的其余部分工作正常,包括注册、登录和配置文件页面。为什么这会是一个许可问题?没错。我得睡觉了。嗯,好吧,我知道我做了什么,之前我尝试过其他几种方法来解决同样的问题,但我会解决你说的问题,然后再试一次。我已经解决了这个问题,并使用了与注册验证完全相同的方法,我不明白为什么验证没有输出错误。
/**
 * Create a new Validator instance.
 *
 * @param  array  $data
 * @param  array  $rules
 * @param  array  $messages
 * @return \Illuminate\Validation\Validator
 */
public function make(array $data, array $rules, array $messages = array(), array $customAttributes = array()) { ... }