Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.68k stars 1.74k forks source link

Undefined Variable on Cart::search() #191

Closed agyto closed 8 years ago

agyto commented 8 years ago

it's turn error when i declare a variable before use Cart::search() method,

$var = 1;
Cart::instance('_wishlist')->search(function ($cartItem, $rowId) {
   if($cartItem->id === $var){ 
      return $var;
    }
}

i try use passing method by filter() on Laravel, but same result

$var = 1;
Cart::instance('_wishlist')->content()->filter(function ($cartItem) {
   if($cartItem->id === $var){ 
      return $var;
    }
}
Crinsane commented 8 years ago

That's because the $var is set in another scope. Look at the php documentation, you'll have to add a 'use' keyword to add the variable to the scope of the closure.