【问题标题】:How to fix Laravel 7 redirect causing 405 error?如何修复 Laravel 7 重定向导致 405 错误?
【发布时间】:2020-09-13 18:13:40
【问题描述】:

我要做的是在删除记录后,重定向回某个页面并显示成功消息。我得到的错误是重定向导致“405 方法不允许错误”。如果我删除重定向删除工作正常。

我的删除方法

public function destroy($id){
    $customer = Customer::find($id);
    $customer->delete();
    return redirect()->route('customers.index')->with('success','Customer deleted');
}

我尝试过的其他重定向方法

return redirect()->action('CustomerController@index')->with('success', 'Customer deleted');
redirect('pages.customers.index')->with('success', 'Customer deleted');
return redirect()->to('/customers')->with('success', 'Customer deleted')->send();

路由配置

Route::resource('customers', 'CustomerController');

我的索引方法

public function index()
{
    $customers = Customer::all();
    return view('pages.customers.index', compact('customers'));
}

根据我在其他帖子上阅读的内容,重定向时使用了错误的方法,有没有办法可以指定使用哪种方法?

【问题讨论】:

  • 你能发布php artisan route:list的相关输出吗?
  • 当然,我已经在问题中添加了它的快照。
  • 这很有趣。你能找到我们触发 405 的异常的来源吗?像 Debugbar 一样,或者从 Laravel 的异常处理程序的 internalDontReport 列表中暂时删除 HttpException
  • 试试这个。 return redirect('customers')->with('success', 'Customer deleted');
  • @Dan 我的 handler.php 文件没有像该示例那样的 internalDontReport 变量。至于 Debugbar,我将不得不研究如何将其集成到我的项目中。

标签: php laravel redirect eloquent http-status-code-405


【解决方案1】:

一切正常,试试php artisan route:clear

【讨论】:

    猜你喜欢
    • 2017-10-07
    • 2020-07-21
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多