php - How Do I Pass Which Item I Want To Delete?
I've inherited this code and fairly new to Laravel. But we have a cart and we can add items to the cart. But the part to delete items from the cart isn't working. Each line has a delete Remove button. But somehow needs to pass to the controller which item it needs to remove.
the cart.blade.php has:
@foreach($custom_quote_items as $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' => '[email protected]', '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 as $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 was not removed.');
}
}
The line: $custom_quote_item = CustomQuoteItem::find(Input::get('id')); returns back null so I know the id isn't working but neither is the name. So figured it's on the blade side.