同じ入力を検証するが、最大数値が異なるため、検証変数を作成したいと思います。したがって、これが問題です。たとえば、最大数値400または1000の変数検証があります。400を超えて拒否すると想定されるフィールドに500を入力すると、完全に正常に機能します。しかし、最大400を検証した後、最大1000を許可すると想定されるフィールドを検証しようとしましたが、現在は400に制限されています。
ストア機能は次のとおりです。
public function store(Request $request)
{
$client_id = $request->client_id;
$client_package_id = $request->client_package_id;
$sale_type_id = $request->sale_type_id;
$max_topup_amount = $request->max_topup_amount;
if($sale_type_id == 3){
$validator = Validator::make($request->all(), [
'amount' => 'numeric|min:0|max:' . $max_topup_amount,
]);
if ($validator->fails()) {
return redirect('/sales' . '/' . $client_id)
->withErrors($validator)
->withInput();
}
$Invoices = new Invoices;
$Invoices->client_id = $client_id;
$Invoices->sale_type_id = $sale_type_id;
$Invoices->item_id = $client_package_id;
$Invoices->total_price = $request->amount;
$Invoices->status = 'Payment Pending';
$Invoices->save();
};
return redirect('/sales' . '/' . $client_id);
ビューは次のとおりです。
@if(count($Client_Packages) > 0)
@foreach($Client_Packages as $c)
<tbody>
<tr>
<td>{{$c->id}}</td>
<td>{{$c->package}}</td>
<td>{{$c->balance}}</td>
<td>{{$c->status}}</td>
{!!Form::open(['action' => ['SalesController@destroy', $c->id], 'method' => 'POST'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::hidden('type', 'package')}}
{{Form::hidden('status', $c->status)}}
{{Form::hidden('client_id', $c->client_id)}}
<td>
<button type="button" class="btn btn-primary fa" data-toggle="modal" data-target="#topup{{$c->id}}">

</button>
<input type="button" class="btn btn-success fa" value="" onclick="location.href = '/sales/{{$c->id}}';">
{{Form::submit('', ['class' => 'btn btn-danger fas'])}}
</td>
{!!Form::close()!!}
</tr>
</tbody>
@include('Sales.edit')
@endforeach
@else
<p>No Clients Found</p>
@endif
フォーム(Sales.edit)を含むモーダルは次のとおりです。
{!! Form::open(['action' => 'InvoicesController@store', 'method' => 'POST']) !!}
<div class="modal fade" id="topup{{$c->id}}">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header bg-success text-white">
<h4 class="modal-title">Top up Package Serial No. {{$c->id}}</h4>
{{Form::hidden('client_package_id', $c->id)}}
<button type="button" class="close" data-dismiss="modal">× </button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row mt-3">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
{{Form::label('amount', 'Amount($)')}}
{{Form::text('amount', '', ['class' => 'form-control', 'placeholder' => 'SGD'])}}
<p>Max Amount: {{$c->payable}} </p>
{{Form::hidden('max_topup_amount', $c->payable)}}
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
{{Form::hidden('sale_type_id', 3)}}
{{Form::hidden('client_id', $Clients->id)}}
{{Form::submit('Top-up', ['class'=>'btn btn-success'])}}
<button type="button" class="btn btn-danger" data-
dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
前もって感謝します!
検証から-> withInput()を削除すると機能しました。
から:
$validator = Validator::make($request->all(), [
'amount' => 'numeric|min:0|max:' . $max_topup_amount,
]);
if ($validator->fails()) {
return redirect('/sales' . '/' . $client_id)
->withErrors($validator)
->withInput();
}
に:
$validator = Validator::make($request->all(), [
'amount' => 'numeric|min:0|max:' . $max_topup_amount,
]);
if ($validator->fails()) {
return redirect('/sales' . '/' . $client_id)
->withErrors($validator);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加