在laravel中,我有资源控制器:
Route::resource('/student','StudentController');
这是我的视图列表代码:
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
<a href="#">Edit</a> |
<a href="{{ route('student.destroy', ['id' => $model->id]) }}">Link</a>
</td>
</tr>
Conytroller函数我有:
public function destroy($id)
{
echo "ok";
}
我的问题是,当我点击锚按钮(删除)时,它没有找到删除的资源路径。我在这里做错了什么?有人能帮我解决这个问题吗。当我单击delete锚时,它调用resource的show函数,但我希望destroy函数调用click。
使用DELETE方法销毁函数
在你的刀片视图中
@foreach($students as $model)
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
<a href="#">Edit</a> |
<a href="javascript:void(0);" onclick="event.preventDefault();document.getElementById('delete_form').submit();">DELETE</a>
<form id="delete_form" style="display:none" action="{{ route('student.destroy',$model->id)}}" method="POST" >
{{ csrf_field() }}
<input type="hidden" name="_method" value="delete" />
</form>
</td>
</tr>
@endforeach