我有一条资源路线
Route::resource('gramb-excluded'、'CexcludedController'、['only'=
和我的代码来保存数据
<div class="col-lg-4">
<form class="form" method="POST" action="{{ route('climb-excluded.store') }}">
{{ csrf_field() }}
<div class="card">
<div class="card-head style-primary">
<header>Add item</header>
</div>
<div class="card-body floating-label">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name">
<label for="name">Name</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<button type="submit"
class="btn btn-block btn-success ink-reaction">
Add
</button>
</div>
</div>
</div>
</div>
销毁数据的按钮:
{!! Form::open( array('route'=>array('climb-excluded.destroy', $excluded->id),
'method'=>'DELETE')) !!}
<button type="submit"
class="btn ink-reaction btn-floating-action btn-sm btn-danger "
rel="tooltip"
title="Delete">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button
{!! Form::close() !!}
存储方法表单控制器:
public function store(Request $request)
{
$this->validate($request,[
'name' => 'required|max:255'
]);
$excluded = new Cexcluded;
$excluded -> name = $request->name;
$excluded->save();
//redirect to
Session::flash('success','New item sucessfully added !');
return back()->withInput(['tabs'=>'second4']);
}
销毁方法表单控制器:
public function destroy($id)
{
$trekExcluded = Cexcluded::find($id);
$trekExcluded->tours()->detach();
$trekExcluded ->delete();
Session::flash('success','Item sucessfully deleted !');
return back()->withInput(['tabs'=>'second4']);
}
我面临的问题/bug是我可以成功地将第一行插入表中。但当我使用第二个方法时,store方法以某种方式重定向到destroy方法,并删除第一个插入的行。我已经清楚地声明了表单的store-method-in-action属性。
仅供参考:两条路线存在于同一视图/页面中。使用foreach
循环销毁col-md-8
中的方法,同时将方法存储在col-md-4
很明显,表单没有唯一的名称
或id
,因此第二个方法被重定向到destroy方法。这样做:
cex-store-1
cex-destroy-1