那么,我有两个字段。在第一个字段中,我想添加旧数据,在第二个字段中,我想添加新数据,在这些字段下面是一个按钮,点击时将从Mongo表获取数据并更新里面的数据。我试过实现各种逻辑,但仍然没有运气。如能提供任何帮助,我将不胜感激。
这是我的控制器代码:public function updatedockets($dockets){
if (!Session::has('user_id')){
return Redirect::to('/login');
}
$cart = AppModelsCart::where('tracking_no',$dockets)->get()->toArray();
foreach ($cart as $value) {
$cart = AppModelsCart::where('tracking_no')->update(['tracking_no' => $dockets]);
}
}
这是我的视图代码:
<div role="tabpanel" class="tab-pane" id="docket-replace">
<form method="post" id="frmDocket" action="/admin/viewdockets">
{!! csrf_field() !!}
<div>
<div class="form-group">
<textarea id="txtreploaceDockets" name="replacedockets" class="form-control" rows="15" placeholder="Enter old docket(s) here. Don't put more than 1000 docket numbers, all dockets should be comma(,) or new line separated"></textarea>
</div>
</div>
</form>
<form method="post" id="frmDocket" action="/admin/viewdockets">
{!! csrf_field() !!}
<div>
<div class="form-group">
<textarea id="txtreplaceDockets" name="replacedockets" class="form-control" rows="15" placeholder="Enter new docket(s) here. Don't put more than 1000 docket numbers, all dockets should be comma(,) or new line separated"></textarea>
</div>
<div class="form-group">
<div class="text-right pr-sm-15 pb-sm-15">
<button type="button" class="btn btn-primary btn-xs" id="btnReplaceDocketData" onclick="return confirm('Are you sure that you have entered the right docket number?')"> Replace Docket </button>
</div>
</div>
</div>
</form>
</div>
由于您不使用$value
,也许下面的代码可以帮助您:
$cart = AppModelsCart::where('tracking_no', $dockets)
->update(['tracking_no' => $dockets]);
示例:
$course->statuses()->updateOrCreate(
['status_id' => $id],
['status' => $request->get('status'), 'status_type' => Course::class]
);`