【发布时间】:2017-01-18 04:14:19
【问题描述】:
为什么会出现这种情况?这是我所有帐户的索引列表。我只想通过 category.destroy 路由删除特定类别,但它是
index.blade.php
@extends('layouts.master')
@section('title','All Categories')
@section('contents')
<div class="row">
<div class="col-md-8 col-sm-4 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">All Categories</div>
<div class="panel-body">
<article>
<div class="table-responsive-vertical shadow-z-1">
<!-- Table starts here -->
<table id="table" class="table table-hover table-mc-light-blue">
<thead>
<tr>
<th>ID No</th>
<th>Category</th>
<th>Edit/Delete</th>
<th>Status</th>
</tr>
</thead>
@foreach($categories as $category)
<tbody>
<tr>
<td data-title="ID">{{$category->id}}</td>
<td data-title="Name">{{$category->name}}</td>
<td><a href="{{ route('category.edit',$category->id) }}" class="btn btn-primary btn-sm pull-left">Edit</a>
 <a href="{{ route('category.destroy', $category->id) }}" class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
</tbody>
@endforeach
</table>
</div>
</article>
</div>
</div>
</div>
</div>
@endsection
@section('js')
{!!Html::script('assets/js/jquery.min.js')!!}
{!!Html::script('assets/js/bootstrap.min.js') !!}
<script>
$('#flash-overlay-modal').modal();
</script>
<script>
$('div.alert').not('.alert-important').delay(3000).fadeOut(350);
</script>
@endsection
CategoryController.php
public function destroy($id){
$category = Category::findOrFail($id);
$category->delete();
Session::flash('flash_message', 'Task successfully deleted!');
return redirect()->route('category.index');
}
相反,它只显示类别的视图特定条目。不是删除什么的
【问题讨论】:
-
如果你链接到路由,那么你实际上并没有访问那个路由,因为销毁路由不是
GET,而是DELETE,因此你实际上应该创建一个小的表单到销毁路由并使用按钮触发表单操作到实际路由。
标签: php laravel laravel-5 laravel-routing