无法将Illuminate \ View \ Factory类的对象转换为字符串

时间:2019-12-15 17:27:58

标签: laravel laravel-6

我是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');
    }

1 个答案:

答案 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');