【问题标题】:For a form the GET method is not supported for this route对于表单,此路由不支持 GET 方法
【发布时间】:2021-01-01 14:31:52
【问题描述】:

我已经设置了在表单中插入数据的 POST 方法。我也在 web.php 中设置了 POST 方法。但是每当我想通过表单插入数据时,它都会显示不支持 Get 方法。但是我已经在表单和路由中编写了 POST 方法。这是我的代码:

表格:

<form action="{{url('/admin/prescription/store')}}" method="POST"> 
@csrf

Route::post('/admin/prescription/store','prescriptionController@store')->name('prescription.store');

控制器:

public function store(Request $request)
{
    $prescription = new Prescription();
    $prescription->full_name = $request->full_name;
    $prescription->nid = $request->nid;
    $prescription->address = $request->address;
    $prescription->contactNum = $request->contactNum;
    $prescription->health_cond = $request->health_cond;
    $prescription->desc = $request->desc;
    $prescription->save();
     
    return redirect()
        ->route('prescription.store')
        ->with('success','Prescription added Successfully.');
 }

【问题讨论】:

  • 看这个返回redirect() ->route('prescription.store') ->with('success','Prescription added Successfully.');因此,您将通过重定向将闪存数据返回到此路由,因此最终使其获取请求

标签: php laravel forms routes get


【解决方案1】:

这是因为你在 store() 中的重定向,你应该重定向到一个 get Route

【讨论】:

  • 是的,我必须重定向索引页面。谢谢
【解决方案2】:

要对两种类型的请求使用一个路由,您可以这样做:

Route::match(['GET', 'POST'],'/admin/prescription/store', 'ExampleController@store');

【讨论】:

    【解决方案3】:

    这是因为您重定向到帖子路由。重定向作为获取请求工作。

    【讨论】:

    • 谢谢。我可以修复它
    猜你喜欢
    • 2020-09-04
    • 1970-01-01
    • 2020-04-23
    • 2020-12-06
    • 1970-01-01
    • 2019-08-28
    • 2021-04-11
    • 2020-08-06
    相关资源
    最近更新 更多