Laravel:验证无效 - 更新方法

时间:2016-10-02 13:07:15

标签: laravel validation

我在更新方法中遇到验证问题。在创建一个它没关系,但是当我尝试编辑时,验证没有通过。这是它:

public function update($id, array $data)
{   
    $quote = $this->find($id);

    if( isset($data['live_date']) ){
        $data['live_date'] = $this->_parseDate($data['live_date']);
    }

    $this->validator = new QuoteValidator($quote);
    $this->validate($data);

    try{     
        $quote->update($data);
        $quote->tracks()->sync($data['tracks']);
        return true;
    } catch (\Exception $ex){
        Log::error($ex->getMessage());
        throw new ProcessingDataException('An error occured.');
    }   

}

这是我视图中的表单:

<div class="row">
    @if (!isset($qoute) || !isset($quote->live_date))
    <div class="col-md-3">
        {!! Form::label('live_date[date]', 'Go-Live Date', ['class' => 'control-label', 'readonly' => 'readonly'] ) !!}
        {!! Form::text('live_date[date]', \Carbon\Carbon::tomorrow()->format('m/d/Y'), ['class' => 'form-control date-picker']) !!}
    </div>
    <div class="col-md-3">
        {!! Form::label('live_date[time]', 'Go-Live Time', ['class' => 'control-label', 'readonly' => 'readonly'] ) !!}
        {!! Form::text('live_date[time]', \Carbon\Carbon::tomorrow()->format('H:i'), ['class' => 'form-control time-picker']) !!}
    </div>
    <div class="col-md-6"></div>
@else
    <div class="col-md-3">
        {!! Form::label('live_date[date]', 'Go-Live Date', ['class' => 'control-label', 'readonly' => 'readonly'] ) !!}
        {!! Form::text('live_date[date]', \Carbon\Carbon::parse($quote->live_date)->format('m/d/Y'), ['class' => 'form-control date-picker']) !!}
    </div>
    <div class="col-md-3">
        {!! Form::label('live_date[time]', 'Go-Live Time', ['class' => 'control-label', 'readonly' => 'readonly'] ) !!}
        {!! Form::text('live_date[time]', \Carbon\Carbon::parse($quote->live_date)->format('m/d/Y'), ['class' => 'form-control time-picker']) !!}
    </div>
    <div class="col-md-6"></div>
@endif
</div>

当我离开空字段时,它只是抛出异常,但是当所有字段都填充了数据时,无论验证规则如何,都会成功更新。

0 个答案:

没有答案