laravel 控制器更新不工作

laravel controller update not working

我正在使用 RESTful 资源控制器并且更新功能无法正常工作。

如果像这样生成一个 link 并且没有任何反应 http://localhost:8000/medication/3?_token=Sv0mblJUcWppsO6roWiXOzZzcFOqlgMBIzJoy3HW&medicine=a&dosage=a&howOften=aaa&forWhat=a&doctor=a&vaccination=a&shots=a

我的查看代码(仅供测试)是

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                </button>
                <h4 class="modal-title custom_align" id="Heading">Edit Your Medication</h4>
            </div>

            <form role="form" action="/medication/3" method="PUT" class="f1">
            {{ csrf_field() }}
            <div class="modal-body">

                <div class="form-group">
                    <input type="text" name="medicine" class="form-control" placeholder="Medicine">
                </div>
                <div class="form-group">
                    <input type="text" name="dosage" class="form-control" placeholder="Dosage">
                </div>
                <div class="form-group">
                    <input type="text" name="howOften" class="form-control" placeholder="How often do I take it">
                </div>
                <div class="form-group">
                    <input type="text" name="forWhat" class="form-control" placeholder="what it is for?">
                </div>
                <div class="form-group">
                    <input type="text" name="doctor" class="form-control" placeholder="Prescribing Doctor">
                </div>
                <div class="form-group">
                    <input type="text" name="vaccination" class="form-control" placeholder="Vaccination">
                </div>
                <div class="form-group">
                    <input type="text" name="shots" class="form-control" placeholder="Shots">
                </div>
            </div>

            <div class="modal-footer ">
                <button type="submit" class="btn btn-success btn-lg btn-update" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> Update</button>
            </div>
            </form>

        </div><!-- /.modal-content --> 
    </div><!-- /.modal-dialog -->

</div>

控制器代码是

public function update(Request $request, $id)
{
    $row = $id;

    $data = array('medicine' => $request->medicine,
                    'dosage' => $request->dosage,
                    'howOften' => $request->howOften,
                    'forWhat' => $request->forWhat,
                    'doctor' => $request->doctor,
                    'vaccination' => $request->vaccination,
                    'shots' => $request->shots);

    $ex = ProfileInformation::insertInformation($row, $this->user, $this->TABLE_NAME, $data);
    if($ex){//executed properly
        return redirect('/medication');
    } else {
        return redirect('/customer');
    }

}

我没有使用 laravel 的标准 ID 主键,但仍想坚持使用资源控制器。我不明白为什么什么都没有发生。如果有查询错误,那么它至少应该转到我的重定向代码。

它不起作用,因为您设置了 method="PUT"。而是执行以下操作

<form role="form" action="/medication/3" method="POST" class="f1">
        {{ csrf_field() }}
        {{ method_field("PUT") }}