如何通过我要删除的项目?

时间:2015-07-08 12:10:58

标签: php forms laravel

我继承了这段代码,对Laravel来说相当新。但我们有一个购物车,我们可以添加项目到购物车。但是从购物车中删除商品的部分无效。每行都有一个删除删除按钮。但不知何故需要将控制器需要移除的控制器传递给控制器 cart.blade.php有:                 @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' => '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

CustomQuoteController.php有

    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.');

    }

}

行:$ custom_quote_item = CustomQuoteItem :: find(Input :: get('id'));返回null,所以我知道id不起作用但名称也不行。所以想到它就在刀片方面。

0 个答案:

没有答案