检查旧数据是否为空或通过输入 laravel Blade 的 isset() 检查

在控制器验证后如何检查旧数据是否可用?我用过这个但它显示错误


@if(\Illuminate\Http\Request::old('status')!=null)

    <option style="display: none" value="{{old('status')}}" hidden>{{old('status')}}</option>

@endif

也用过这个


@if(isset(old('status')))

    <option style="display: none" value="{{old('status')}}" hidden>{{old('status')}}</option>

@endif

完整形式是


<form action="{{route('add-expense-store')}}" method="post" class="new-added-form">

    {{ @csrf_field() }}

    <div class="row">

        <div class="col-xl-8 col-lg-8 col-12 form-group">

            <label>Expense Type</label>

            <select class="select2" name="type">

                <option value="">Please Select</option>

                {{--<option value="Teacher's Salary">Teacher's Salary</option>

                <option value="Staff's Salary">Staff's Salary</option>--}}

                <option value="Transport">Transport</option>

                <option value="Mobile Bill">Mobile Bill</option>

                <option value="Utility Bill">Utility Bill</option>

                <option value="Stationary">Stationary</option>

                <option value="Print & Press">Print & Press</option>

                <option value="Photocopy & Compose">Photocopy & Compose</option>

                <option value="Entertainment & Hospitality">Entertainment & Hospitality</option>

                <option value="Donation">Donation</option>

                <option value="Program">Program</option>

                <option value="Personal or Owner">Personal or Owner</option>

            </select>

        </div>


两者都出错。我如何检查我们在刀片中是否可用的旧值?


现在我包括我的表单数据。如果找不到旧值,我想在这里隐藏。请帮忙解决这个问题。检查刀片中的旧数据。


holdtom
浏览 92回答 1
1回答

杨__羊羊

您可以通过这种方式进行检查。记得从控制器以这种方式返回它&nbsp;$validator = $this->validate($request, [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'type' => 'required',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'status' => 'required'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]);if ( $validator->fails() ) {&nbsp; &nbsp; &nbsp; &nbsp; return back()->withErrors( $validator )->withInput();&nbsp; &nbsp; }在你看来这样做<select class="select2" name="status">&nbsp; &nbsp;<option value="">Please Select</option>&nbsp; &nbsp;<option value="Paid" {{ old('status') == 'Paid' ? 'selected' : '' }}>Paid</option>&nbsp; &nbsp;<option value="Due" {{ old('status') == 'Due' ? 'selected' : '' }}>Due</option></select>
打开App,查看更多内容
随时随地看视频慕课网APP