php - How Do I Pass Which Item I Want To Delete? -
i've inherited code , new laravel. have cart , can add items cart. part delete items cart isn't working. each line has delete remove button. somehow needs pass controller item needs remove.
cart.blade.php has: @foreach($custom_quote_items $custom_quote_item)
<tr> <td><p>{{ $custom_quote_item->name }}</p></td> <td><p>{{ $custom_quote_item->description }}</p></td> <td><p>{{ intval($custom_quote_item->quantity) }}</p></td> <td><p>{{ $custom_quote_item->pricing($custom_quote_item->name) }}</p></td> <td> <p> {{ form::open(array('action' => 'customquotecontroller@removefromquote', 'method' => 'delete')) }} {{ form::hidden('id', $custom_quote_item->id) }} {{ form::submit('remove', array('class'=>'btn btn-default')) }} {{ form::close() }} </p> </td> </tr> @endforeach
the customquotecontroller.php has
public function removefromquote() { $item_exists = true; // $custom_quote_item = customquoteitem::find(input::get('id')); $custom_quote_item = customquoteitem::find(input::get('name')); // $custom_quote_item = customquoteitem::find(197); print(input::get('id')); print("end name\n"); $custom_quote_items = session::get('custom_quote_items'); if(count($custom_quote_items) > 0 ) { foreach($custom_quote_items $key => $item_in_cart) { dd($item_in_cart); if($item_in_cart->name == $custom_quote_item->name) { unset($custom_quote_items[$key]); session::set('custom_quote_items', $custom_quote_items); return redirect::back()->with('success', 'item has been removed.'); } } } return redirect::back()->with('errors', 'item not removed.'); } }
the line: $custom_quote_item = customquoteitem::find(input::get('id')); returns null know id isn't working neither name. figured it's on blade side.
Comments
Post a Comment