我正在尝试创建一种情况,用户可以加载页面,选择时间表编号,然后让系统删除与该时间表编号关联的所有记录。此函数加载表单页面:
public function deletetimesheetLoad()
{
$timesheets = collect(DB::select("SELECT dbo.TIME.Source AS Source
FROM dbo.TIME
GROUP BY dbo.TIME.Source
ORDER BY dbo.TIME.Source ASC"));
return view('utilities/deletetimesheet',['timesheets' => $timesheets]);
}
这是实际的刀片模板:
<form method="post"
action="{{url('/time/deletetimesheet/process')}}"
enctype="multipart/form-data"
<div class="form-group">
<label class="col-md-12 control-label" for="TIMESHEETNUMBER">Timesheet Number</label>
<div class="col-md-12">
<select required id="TIMESHEETNUMBER" name="TIMESHEETNUMBER" class="form-control select2_field">
<option value=""></option>
@foreach ($timesheets as $row)
<option value="{{ $row->Source }}">{{ $row->Source }}</option>
@endforeach
</select>
</div>
</div>
<div id="saveActions" class="form-group">
<input type="hidden" name="save_action" value="Submit">
<div class="btn-group">
<button type="submit" class="btn btn-success">
<span class="fa fa-save"></span>
<span data-value="Submit">Submit</span>
</button>
</div>
<a href="" class="btn btn-default"><span class="fa fa-ban"></span> Cancel</a>
</div>
这是表单操作指向的函数:
public function deletetimesheetProcess(TimesheetRequest $request)
{
DB::table('TIME')->where('Source', $request->get('TIMESHEETNUMBER'))->delete();
\Alert::success(trans('yay'))->flash();
return view('details/customershow',[]);
}
以下是两个函数的已定义路由:
Route::get('/time/deletetimesheet', 'Admin\TimeCrudController@deletetimesheetLoad');
Route::post('/time/deletetimesheet/process', 'Admin\TimeCrudController@deletetimesheetProcess');
目前,刀片模板正确加载,并且不会在提交时抛出错误 - 只需重新加载当前页面即可。我做错了什么?