lundi 20 février 2017

laravel controller update not working

i am using RESTful Resource Controllers and update function is not working properly.

if generate a link like this and nothing happens http://localhost:8000/medication/3?_token=Sv0mblJUcWppsO6roWiXOzZzcFOqlgMBIzJoy3HW&medicine=a&dosage=a&howOften=aaa&forWhat=a&doctor=a&vaccination=a&shots=a

my view code(for testing only) is

            <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">
            
            <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>

Controller code is

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');
    }

}

I'm not using that standard id primary key of laravel but still want to stick with resource controller. i don't understand why nothing is happening. if there is a query error then it should atleast go to my redirect code.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire