【发布时间】:2014-06-05 19:27:39
【问题描述】:
对于显示的每个结果,我希望有一个关联的删除操作。
在foreach 循环内我有:
{{ Form::open(array('route' => array('archive', $alert->id), 'role'=>'form')) }}
<table class="tablesorter table-responsive" id="alerts">
<thead>
<tr>
<th class="header">ID</th>
<th class="header">Archive</th>
</tr>
</thead>
<tbody>
@foreach($alert->alerts as $alert)
<tr>
<td><button type="submit" class="btn btn-warning" name="archive">Archive</button></td>
</tr>
@endforeach
</tbody>
</table>
{{ Form::close() }}
路线:
Route::post('agents/destroy/{id}',
array('as' => 'archive', 'uses' => 'AgentsController@postDestroy'));
销毁函数:
public function postDestroy($id)
{
$alert = Alert::find($id);
$alert->delete();
}
当我dd($id) 时,它返回 null,就好像它没有从提交按钮中获取 'id'。
任何帮助将不胜感激。
【问题讨论】:
标签: php laravel laravel-4 foreach