【发布时间】:2021-09-03 08:42:30
【问题描述】:
我有一个系统,用户在该系统中输入从和到的日期范围,并获取该日期范围之间的所有必需数据。从数据库中检索的数据显示在每行包含复选框的表中。当用户选中复选框并将其更新的数据提交到数据库时,但我必须在更新数据库中的数据后重定向到同一个表。它说这条路线不支持 GET 方法。支持的方法:POST。需要帮助。
这是我的日期范围填充视图。
@extends('master')
@section('content')
<div class="input-group" style="margin:50px">
<table>
<form action="/payment_list_table" method="POST">
@csrf
<div class="form-outline">
<tr>
<th>
<label>From</label>
</th>
<th>
<input type="date" name= 'from' class="form-control" placeholder="Doc Received Date" required="" />
</th>
<th>
<label>To</label>
</th>
<th>
<input type="date" name= 'to' class="form-control" placeholder="Doc Received Date" required="" />
</th>
</tr>
<th>
<button type="submit" class="btn btn-success">
<i class="fas fa-search"></i>
</button>
</th>
</div>
</form>
</table>
</div>
@endsection
这是我的搜索表视图
@extends('master')
@section('content')
<div class='container' style="margin-top:50px">
<div class="row">
<div class="input-group" style="margin:20px">
<form>
<table style="float:right">
<th>
<div class="form-outline">
<input type="search" id="form1" class="form-control" placeholder="Search"/>
</th>
</form>
</div>
<form method="POST">
@csrf
<button type="submit" formaction="#" name="submit" class="checklistpo">PO</button>
<button type="submit" formaction="#" name="submit" class="ajax.po">AO</button>
<div class="table-responsive">
<table class="table custom-table">
<thead>
<tr>
<th scope="col">
<label class="control control--checkbox">
<input type="checkbox" class="js-check-all"/>
<div class="control__indicator"></div>
</label>
</th>
<th scope="col" >S.N</th>
<th scope="col">LC NO</th>
<th scope="col">Applicant</th>
<th scope="col">Doc Value</th>
<th scope="col">Doc Received date</th>
<th scope="col">LC Type</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $number = 1;?>
@foreach($datas as $items)
<tr>
<td><input type="checkbox" name="checkboxlist[]" value="{{$items->id}}" /></td>
<td>{{$number}}</td>
<td>{{$items->lc_no}}</td>
<td>{{$items->applicant}}</td>
<td>{{$items->doc_value}}</td>
<td>{{$items->rec_date}}</td>
<td>{{$items->sight_usance}}</td>
</tr>
<?php $number++; ?>
@endforeach
</tbody>
</table>
</div>
</form>
</div>
</div>
@endsection
这是我的控制器
function po(Request $req){
$validate=Validator::make($req->all(), [
"checkboxlist" => "required|array"
]);
foreach($req->checkboxlist as $list){
$data = Doc::find($list);
$data->payment_comment = "PO";
$data->Payment_status = "Prepared";
$data->save();
};
return Redirect::back();
if($validate->fails()){
return redirect()->back()->with("errors",$validate->errors());
}
}
还有我的路线
Route::post('po', [PaymentController::class, 'po']);
【问题讨论】:
-
你想重定向回这条路线
Route::post('po',[PaymentController::class, 'po']);?如果是这样,那么你不能 -
应该是简单的
return back()->with(...);您没有指定要重定向到的路线,因此您没有任何理由收到该错误。你从哪条路线发帖?典型的流程是GET请求查看表单 ->POST请求 ->REDIRECT->GET到您发布的表单。 -
@Espresso 那么我怎样才能让用户重定向到表格页面...
-
return redirect()->route('route_to_table_page'),但目前没有理由让您收到该错误。 -
@TimLewis 一个问题......页面如何知道我第一次插入的相同日期范围以在刷新后到达表格。
标签: laravel laravel-8 laravel-routing