我只是想制作一个从数据库中删除模型记录的简单表单。我以前做过,但下面的代码只闪烁成功消息并重定向。记录永远不会离开数据库。
这是我的表格:
@foreach ($users as $user)
<li class="list-group-item {{($loop->iteration % 2 == 0) ? 'even' : 'odd'}}">
<h3>{{$user->first_name}} {{$user->last_name}}</h3>
<b>AccessID: </b> {{$user->id}} <br />
<b>Created: </b> {{$user->updated_at}}
<form action="{{ url('/users/delete', ['id' => $user->id]) }}" method="post">
<input type="hidden" name="_method" value="delete" />
{!! csrf_field() !!}
<button type="submit">Delete</button>
</form>
</li>
@endforeach
这是我的控制器方法:
public function destroy(User $user)
{
$user->delete();
Session::flash('action', 'Deleted');
Session::flash('status', $user->first_name . $user->last_name .'’s access successfully removed.');
return redirect('/users');
}
这是我的路线:Route::delete('/users/delete/{id}', 'UserController@destroy');