Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item not remove #129

Open
SknightS opened this issue Mar 27, 2018 · 7 comments
Open

Item not remove #129

SknightS opened this issue Mar 27, 2018 · 7 comments

Comments

@SknightS
Copy link

$cartid = $r->cartid;
// return $cartid;
Cart::remove($cartid);

i am trying like this . but item not remove from cart . what can be the issue ?

@frezno
Copy link
Contributor

frezno commented Mar 27, 2018

@SknightS $cartid is the ID of what, of the item (product) you want to delete?
what result does dd($cartid); show? Is it the ID of the item you want to be removed?

@SknightS
Copy link
Author

yes its the item id . its showing nothing .

@frezno
Copy link
Contributor

frezno commented Mar 28, 2018

if dd doesn't give you a result, it means that the item id isn't provided, ie there's something wrong with your code.

for displaying your items in the cart, you use $cartCollection = Cart::getContent(); and pass the result to your view and loop through it, eg

@foreach ($cartCollection as $cart)
    <tr>
        <td>{{ $cart['name'] }}<td>
        <td>{{ $cart['qty'] }}<td>
        <td>{{ $cart['price'] }}<td>
        <td><a class="btn btn-danger" href="{{ url('/remove/'.$cart['id']) }}">X</a><td>
    </tr>
@endforeach

in your web.php file you've to add the route:
Route::get('remove/{id}', 'CartController@removeFromCart');

and the removeFromCart method:

public function removeFromCart($id)
{
    Cart::remove($id);

    return back();
}

that way it shouldn't be a problem to delete an item from the cart

@SknightS
Copy link
Author

thanks for your help .

but i did it with ajax . i pass the id with ajax and in controller i remove the item .
yes i show that item is in the cart .

is it the problem of ajax controller ?

@frezno
Copy link
Contributor

frezno commented Mar 28, 2018

sorry, don't know how to handle ajax

@darryldecode
Copy link
Owner

@SknightS please post your codes or you can always check the demo repo here https://github.com/darryldecode/laravelshoppingcart-demo this is ajax.

@Generallisimo
Copy link

if dd doesn't give you a result, it means that the item id isn't provided, ie there's something wrong with your code.

for displaying your items in the cart, you use $cartCollection = Cart::getContent(); and pass the result to your view and loop through it, eg

@foreach ($cartCollection as $cart)
    <tr>
        <td>{{ $cart['name'] }}<td>
        <td>{{ $cart['qty'] }}<td>
        <td>{{ $cart['price'] }}<td>
        <td><a class="btn btn-danger" href="{{ url('/remove/'.$cart['id']) }}">X</a><td>
    </tr>
@endforeach

in your web.php file you've to add the route: Route::get('remove/{id}', 'CartController@removeFromCart');

and the removeFromCart method:

public function removeFromCart($id)
{
    Cart::remove($id);

    return back();
}

that way it shouldn't be a problem to delete an item from the cart

ThankssSSS!!!!!Bro - you best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants