我的Laravel应用程序没有清空错误包

时间:2019-06-28 15:18:42

标签: laravel laravel-blade laravel-5.8

我的Laravel应用程序即使显示验证错误也不会清除它们。当我导航并返回到表单以创建新记录时,错误仍在显示。我怎样才能解决这个问题?下面是我显示错误的方式。

@if ($errors->has('uuids'))
    <div class="row">
        <div class="col-md-offset-3 col-md-6 text-center">
            <div class="alert alert-warning text-white text-bold">
                @foreach ($errors->get('uuids') as $error)
                    <p>{{ $error }}</p>
                @endforeach
            </div>
        </div>
    </div>
@endif

2 个答案:

答案 0 :(得分:0)

我在这里创建了示例,并且工作正常:-

Route::get('/formTest',function (){
    return view('testForm');
});

Route::post('/formSubmit',function (Request $request){
    if($request->get('uuids') === null){
        $message = [
            'required' => 'Name is required',
            'number'   => 'And It should be number'
        ];
    }else{
        dd($request->get('get'));
    }
    return redirect()->back()->withErrors(['uuids' => $message]);    
})->name('submitForm');

刀片

<form method="POST" action="{{  route('submitForm') }}">
    @csrf
    <input type="text" name="uuids">
    @if($errors->has('uuids'))
        @foreach($errors->get('uuids') as $key => $value)
        <br>
        {{  $key.'----'.$value }}
        <br>
        @endforeach
    @endif
    <button type="submit">SUBMIT</button>
</form>

enter image description here

答案 1 :(得分:0)

如果您使用了错误配置的缓存依赖项,则会发生此错误