Laravel 5 如何使用html标记在Laravel5中传递参数?

Laravel 5 如何使用html标记在Laravel5中传递参数?,laravel-5,Laravel 5,嗨,我是laravel5的新手,在HTML代码中,我需要调用下面的destroy函数。这是我在控制器页面上写的 有人能帮我吗 public function destroy($id) { Book::find($id)->delete(); return Redirect::route('books.index')->withInput(); } 您正试图返回$input(withInput),但它不可用,因为您没有创建它 似乎要返回已删除的记录?如果要返回已删除的

嗨,我是laravel5的新手,在HTML代码中,我需要调用下面的destroy函数。这是我在控制器页面上写的

有人能帮我吗

public function destroy($id)
{
    Book::find($id)->delete();
    return Redirect::route('books.index')->withInput();
}

您正试图返回$input(withInput),但它不可用,因为您没有创建它

似乎要返回已删除的记录?如果要返回已删除的数据,可以执行以下操作:

public function destroy($id)
{
    // First get the data
    $data = Book::find($id);
    // Then delete it
    Book::find($id)->delete();
    // Finally return it
    return Redirect::route('books.index')->withData();
}
或者您可以在一行中尝试(不确定是否有效):

public function destroy($id)
{
    $data = Book::find($id)->delete();
    return Redirect::route('books.index')->withData();
}