dimanche 5 août 2018

on update method getting error

I am trying to perform UPDATE operation but getting error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException. Getting this error when I press the UPDATE button for data update. I can not understand the error reason. Please help!!!

controller block update method

public function update(Request $request, $id)
    {
        $book = Book::find($id);
        $book -> BookName = $request->get('NBookName');
        $book -> BookID = $request->get('NBookId');
        $book -> BookUnitPrice = $request->get('NBookUnitPrice');
        if($book->save())
            {
                return redirect()->route('pages.book')->with('alert-success', 'books updated successfully.'); 
            }  
            else
            {
                return redirect()->back()->with('alert-success',$error->getMessage()); 
            }
    }

update page

<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data">
                
                <input type="hidden" name="_method" value="PATCH"/>


        <div class="row" style="padding-left: 1%;">
                <div class="col-md-4">
                    <div class="form-group">
                        <label>Book Name</label><span class="required">*</span>
                        <input type="text" value="" maxlength="100" minlength="3" autofocus="autofocus" autocomplete="off" required="required" name="NBookName" class="form-control"/>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group" style="padding-left: 5%;">
                        <label>Book ID</label><span class="required">*</span>
                        <input type="text" value="" maxlength="10" minlength="1" autocomplete="off" required="required" name="NBookId" class="form-control"/>
                    </div>    
                </div>
                <div class="col-md-4">
                    <div class="form-group" style="padding-left: 5%;">
                        <label>Unit Price</label><span class="required">*</span>
                        <input type="text" value="" maxlength="5" required="required" autocomplete="off" runat="server" name="NBookUnitPrice" class="form-control" onkeypress="return decimalOnly(event)"/>
                    </div>                                   
                    <div class="form-group" style="padding-left: 5%;">
                        <button type="submit" class="btn btn-primary">Update</button>        
                    </div>                                      
                </div>
        </div>
</form> 

Route list

// for books
Route::get('/book','BookController@create');
Route::post('/book','BookController@store');
Route::get('/book/{id}','BookController@edit');
Route::put('/book/{id}', 'BookController@update');

Please see the image attached for the error page. enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire