vendredi 3 août 2018

single form for insert and update data

I am trying to use single form for both data insertion and data update. But I do not know how can it be done. In my form I've mentioned the action method action="", but I want to use the same form for data insertion and data update.

//book.blade.php
<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data">
                        
                <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" 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>Unit Price</label><span class="required">*</span>
                                <input type="text" maxlength="5" required="required" autocomplete="off" runat="server" name="NBookUnitPrice"/>
                            </div>                                   
                            <div class="form-group" style="padding-left: 5%;">
                                <button type="submit" class="btn btn-primary">Submit</button>        
                            </div>                                      
                        </div>
                </div>
        </form>

controller code

public function edit($id)
    {

            $book = Book::find($id);
            return view('pages.book',compact('book','id'));

    }

route page

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

I do not know how to process it further.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire