【问题标题】:Laravel - How to properly route a button to a controller function?Laravel - 如何正确地将按钮路由到控制器功能?
【发布时间】:2019-03-23 09:32:48
【问题描述】:

所以我有一个按钮可以重定向到确认删除路线:

<td align="center"><button type="button" data-href="{{route('head.sale.h_2_101@confirmDelete', ['id' => $No-1])}}" class="btn btn-xs btn-success">Confirm Delete</button></td>

我也在web.php中设置了路由:

Route::match(['get', 'post'], 'head/sale/h_2_101/confirmDelete/{id}', 'head\sale\h_2_101@confirmDelete')->name("head.sale.h_2_101@confirmDelete")->middleware('auth');

它重定向到 h_2_101.php 控制器内部的这个函数:

public function comfirmDelete($id) {
    View::share('deleteUrl', route('head.sale.h_2_101@delete', ['id' => $id]));
    View::share('backUrl', "javascript:history.back()");

    return redirect()->back()->withInput();
}

但是当我按下确认删除按钮时,它给了我这个错误:

我错过了什么吗?

【问题讨论】:

  • 您的命名空间设置是否正确?应该是namespace App\Http\Controllers\head\sale;。你的班级是class h_2_101 extends Controller { ... } 吗?显示您的控制器声明。

标签: php laravel-5


【解决方案1】:

您在控制器中的方法是comfirmDelete,而在路由中是confirmDelete,这就是问题所在。

【讨论】:

    【解决方案2】:

    您在 route 上写了 confirmDelete 的类型错误,但函数名称是 co'm'firmDelete。

    【讨论】:

      猜你喜欢
      • 2017-06-09
      • 2021-09-06
      • 2018-01-09
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多