php - How Do I Pass Which Item I Want To Delete?

545

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.

People are also looking for solutions to the problem: php - Auto secure form on Laravel 4.2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.