我正在尝试从数据信息中删除数据,但它没有删除。有什么办法吗?删除按钮位于编辑按钮下方。而destroy函数位于infoController.php
中Index.blade.php
<!DOCTYPE html>
<html>
<head>
<title>All userinfo</title>
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row col-md-6 col-md-offset-2 custyle">
<table class="table table-striped custab">
<thead>
<a href="userinfo/create" class="btn btn-primary btn-xs pull-right"><b>+</b> Add new categories</a>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Hometown</th>
<th class="text-center">Action</th>
</tr>
</thead>
@foreach($alldata as $data)
<tr>
<td>{{ $data -> id }}</td>
<td>{{ $data -> name }}</td>
<td>{{ $data -> email }}</td>
<td>{{ $data -> age }}</td>
<td>{{ $data -> hometown }}</td>
<td class="text-center"><a class='btn btn-info btn-xs' style="margin-bottom:5px" href="{{route('userinfo.edit',$data->id)}}"><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a href="{{route('userinfo.destroy',$data->id)}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span> Delete</a></td>
</tr>
@endforeach
</table>
{!! $alldata -> render(); !!}
</div>
</div>
</body>
</html>
infoController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\infomodel;
class infoController extends Controller
{
public function index()
{
$alldata = infomodel::paginate(4);
return view('userinfo.index', compact('alldata'));
}
public function create()
{
return view('userinfo.create');
}
public function store(Request $request)
{
$input = $request->all();
infomodel:: create($input);
return redirect('userinfo');
}
public function show ()
{
}
public function edit($id)
{
$updateinfo = infomodel::findorfail($id);
return view('userinfo.edit', compact('updateinfo'));
}
public function update(Request $request, $id)
{
$input = $request -> all();
$data = infomodel::findorfail($id);
$data -> update($input);
return redirect('userinfo');
}
public function destroy ($id)
{
$data = infomodel::findorfail($id);
$data -> delete();
return redirect('userinfo');
}
}
路线/ web.php
<?php
Route::resource('userinfo','infoController');
Route::get('/solid', function () {
return view('solid.index');
});
答案 0 :(得分:5)
您正在使用resource controller,因此您需要使用Delete
方法,例如:
{!! Form::open(['method' => 'Delete', 'route' => ['someroute.destroy', $id]) !!}
<button type="submit">Delete</button>
{!! Form::close() !!}
或者,您应该使用其他Get
路线:
Route::get('delete/{id}', 'MyController@deleteInfo');