在laravel 6中,以post方法发送表单数据会导致错误,因为此路由不支持POST方法。支持的方法:GET,HEAD

时间:2019-09-27 14:49:02

标签: php laravel laravel-blade laravel-6 laravel-form

我尝试将整个表单数据作为post方法存储到post方法中的路由中,出现以下错误

此路由不支持POST方法。支持的方法:GET,HEAD。

请看下面的代码

web.php

 Route::get('/purchase/index','PurchasesController@index')->name('purchase.index');
 Route::get('/purchase/create','PurchasesController@create')->name('purchase.create');
 Route::post('/purchase/store','PurchasesController@store')->name('purchase.store');

create.blade.php

@extends('layouts.nav') @section('content')

<div class="container  mt-3 border ">
    <div class="row  justify-content-center align-items-center" style="background-color:teal;color:#fff;">

        <h1> Purchase Details</h1>
    </div>
    {!!Form::open(['route'=>['purchase.store'],'id'=>'purchase_form','method'=>'POST'])!!}

    <div class="container">
        <div class="row   float-left m-3">
            {{-- {!!Form::open(['route'=>['purchase.store'],'id'=>'purchase_form','method'=>'POST'])!!} --}}

            <form>
                Date:
                <input type="date" date-format="mm-dd-yyyy" placeholder="MM-DD-YYYY" name="date" id="datePicker">

            </form>
        </div>
        <!-- <div class="col-sm-4 pull-right " style="margin-top:5px;margin-bottom:5px;">-->
        <div class="row  justify-content-center float-right m-3">

            <button type="button" class="btn btn-info add-new" id="addnew"><i class="fa fa-plus"></i> Add New</button>

        </div>
    </div>
    <div class="container mt-3">
        <form method="POST" action=" ">
            <table class="table table-bordered" id="tb2">
                <thead class="text-center">
                    <tr class="tr-header">
                        <th>CI No</th>
                        <th>ItemName</th>
                        <th>Unit</th>
                        <th>Price</th>
                        <th>SubTotal</th>
                        <th>Actions</th>
                    </tr>
                </thead>

                <tbody>
                    <tr>

                        <td class="clid"></td>
                        <td>
                            <input type="text" class="form-control name" name="name" id="inputGroupSelect01">
                        </td>
                        <td>
                            <input type="text" class="form-control qty" name="qty" id="qty">
                        </td>
                        <td>
                            <input type="text" class="form-control rate" name="rate" id="rate">
                        </td>
                        <td>
                            <input type="text" class="form-control subTotal" name="subTotal" id="subTotal">
                        </td>

                        <td> <a class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a> </td>
                    </tr>
                </tbody>
            </table>

    </div>
    <div class="float-right m-3">
        {{-- {!!Form::submit('Submit');!!} --}}
        <form method="POST" action="/purchase/store">
            <button type="submit" name="edit" class="btn btn-primary ">Submit</button>
        </form>
    </div>
    <div class=" float-right m-3">
        <h5><b>Grand Total</b></h5>
        <input type="text-box" class="grandTotal" maxlength="10" size="10">
    </div>

</div>

</div>
{!!Form::close()!!} @stop

PurchasesController.php

 public function store(Request $request)
 {
      //
        return "i have entered store";
 }

2 个答案:

答案 0 :(得分:1)

尝试使用

<form method="POST" action="{{url(purchase/store)}}">

并确保您没有使用前缀组

答案 1 :(得分:0)

如果您使用表单生成器,则可以传递此令牌

{!!形式:: token()!!}

否则,您将此字段传递给

{!! csrf_field()!!}