我是laravel的新手 我在视图blog.blade.php中的删除按钮
<form action="{{route('blog.destroy', $blog->id)}}">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit"><span class = "fa fa-trash" ></span></button>
</form>
在blogController上删除函数
public function destroy($id)
{
Blog::where('id',$id)->delete();
return Redirect::to('blog')->with('success','Blog Deleted');
}
答案 0 :(得分:-1)
尝试此代码
blog.blade.php:
<a href="{{route('blog.destroy', [$blog->id])}}" class="btn btn-danger"><span class = "fa fa-trash" ></span></a>
web.php:
Route::get('/blog/destroy/{id}', 'blogController@destroy')->name('blog.destroy');