laravel - Get the model ID when updating a resource -


i have form submit patch request controller's update method. update method requires have $id, can see below whenever try no query results model [item]. since update method did not receive $id of model

public function update($id)     {         $item = item::findorfail($id);         $update = input::all();             // codes save changes          return redirect::route('items.index');     } 

another thing whenever submit form, url turns this:

mw.dev/items/%7bitems%7d


edit

routes.php

route::resource('items','itemscontroller'); 

itemcontroller

public function edit($id)     {         $item = item::findorfail($id);         return view::make('items.edit')->with('item',$item);     } 

i have included code on edit.blade.php

{{form::open(array('route' => 'items.update', 'method'=>'patch'))}}     {{form::text('barcode', $item->barcode, array('placeholder' => 'barcode'))}}     {{form::text('imei',$item->imei, array('placeholder' => 'imei'))}}     {{form::text('item_name', $item->item_name, array('placeholder' => 'item name'))}}     {{form::submit('edit')}} {{form::close()}} 

you have pass model view , need pass id parameter when generating form. assume have user model , it's available in view. may generate form action using this:

// using form::open method route form::open(array('route' => array('route.name', $user->id)))  // using form::model method route form::model($user, array('route' => array('route.name', $user->id), 'method' => 'patch'))  // using form::open method action form::open(array('action' => array('controller@update', $user->id), 'method' => 'patch'))  // using form::open method url form::open(array('url' => 'something/update/' . $user->id, 'method' => 'patch')) 

check more on opening form.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -