谁能告诉我有没有破坏方法的路线?我试图删除我的记录在表中,但当我点击删除按钮是说我的路线是没有定义我想这就是为什么我的删除操作不工作。
未定义路由[result.Destroyee]。(视图:C:\Users\JohnFrancis\LaravelFrancis\resources\views\account\search.blade.php)
路线
//READ
Route::get('/search',
[
'uses' => '\App\Http\Controllers\AccountController@getEmployee',
'as' => 'account.search',
]);
//EDIT
Route::get('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@editEmployee',
'as' => 'account.edit',
]);
我在编辑路由中传递了id
,因此它将识别当前正在使用的id。
控制器:
//READ
public function getEmployee()
{
$result = DB::table('users')->get();
return view ('account.search')->with('result', $result);
}
//EDIT
public function editEmployee($id)
{
$result = User::find($id);
//key //value
return view ('account.edit')->with('result', $result);
}
//DELETE
public function destroyEmployee($id)
{
$result = User::destroy($id);
return redirect()->route('account.search');
}
搜索刀身php
@foreach ($result as $row)
<tr class = "success">
<td>{{ $row->id }}</td>
<td>{{ $row->first_name }}</td>
<td>{{ $row->last_name }}</td>
<td>{{ $row->middle_name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->username }}</td>
<td>
<a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>
<a href = "{{ route ('result.destroyEmployee', $row->id) }}"><button type = "submit" class = "btn btn-danger">Delete</button></a>
</td>
</tr>
@endforeach
edit.blade.php
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit', $result->id) }}">
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Save</button>
</div>
<input type = "hidden" name = "id" value = "{{ $result->id }}">
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>
将此路线添加到路线中。php
。我不鼓励GET请求中的delete操作,但因为您在锚标记上定义了该操作,所以它将是一个GET请求。
//DELETE
Route::get('/destroy/{id}',
[
'uses' => 'AccountController@destroyEmployee',
'as' => 'result.destroyEmployee',
]);
您没有定义此路由,您正试图点击Archive
按钮点击它