aleksov's avatar

Delete the next $item in cart (laravel crinsane)

I need ability when delete one $item from cart to delete also prevous or the next item...

so :

Cart::remove()

To remove an item for the cart, you'll again need the rowId. This rowId you simply pass to the remove() method and it will remove the item from the cart.

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

Cart::remove($rowId);

this is from documentation.

How I can delete item with $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; and the next item ?

0 likes
5 replies
irsyadadl's avatar

Ok. The first think you need to do is have route like this.

Route::post('cart/remove/{item_id}', 'CartController@remove')->name('cart.remove');

Then you need controller said like this.

class CartController extends Controller
{

    public function remove($item_id)
    {
        \Cart::remove($item_id);
//         flash("Your item has been removed");
        return back();
    }
}

And your form should be.

<form action="{{ route('cart.remove', $item->rowId) }}" method="post" class="form-inline">
    {{ csrf_field() }}
    <button type="submit" class="btn btn-danger btn-sm">
        <span class="glyphicon glyphicon-trash"></span>
    </button>
</form>   

And now you're done :)

aleksov's avatar

I have all this.

I want to delete the next $item when I delete item with $rowID ...

aleksov's avatar

so need to find next item and delete both ...

irsyadadl's avatar

I don't know exactly you mean. The Cart just the delete with one item you're choosing. That's it.

aleksov's avatar

but I send one rowId and I want to delete the next also ...

Please or to participate in this conversation.