$name undefined ?   need insert one line 
$name = $item->name;