Php Laravel Route似乎将我的控制器变量设置为null

Php Laravel Route似乎将我的控制器变量设置为null,php,laravel,controller,routes,Php,Laravel,Controller,Routes,我有一条到我的CartController的路线,如下所示: Route::get('setDropDownIndex/{index}', 'CartController@setDropDownIndex'); 在myCartController中: public function setDropDownIndex($index) { $this->dropDownIndex = $index; //echo $this->dropDownIndex; return r

我有一条到我的
CartController
路线,如下所示:

Route::get('setDropDownIndex/{index}', 'CartController@setDropDownIndex');
在my
CartController
中:

public function setDropDownIndex($index)
{
  $this->dropDownIndex = $index;
  //echo $this->dropDownIndex;
  return redirect('cart');
}

public function cart()
{
$this->getPayPalOptions();

$data = array(
  'ppCode'  => $this->ppCode,
  'estOmnivaValue'  => $this->estOmnivaValue,
  'estSmartValue'  => $this->estSmartValue,
  'europeValue'  => $this->europeValue,
  'rowValue'  => $this->rowValue,
  'estOmnivaText'  => $this->estOmnivaText,
  'estSmartText'  => $this->estSmartText,
  'europeText'  => $this->europeText,
  'rowText'  => $this->rowText,
  'dropDownIndex' => $this->dropDownIndex
);

return View::make('pages.cart', ['active'=>'navCart'])->with($data);
} 
Route
工作正常,我可以
echo
确认
setDropDownIndex
正确地“保存”
$this->dropDownIndex
。问题是我的
重定向到
购物车
似乎破坏了我的
$this->dropDownIndex
,将其设置为空


我对
Laravel
很陌生,谁能告诉我如何“持久化”
$this->dropDownIndex
?当我执行重定向时,是否应将
一起使用?

对于持久化
$index
值,您可以使用会话。否则,在重定向后,它将再次重定向到该路由,它将进入该控制器的cart函数,当它进入
cart()
时,它将不会进入setDropDownIndex($index)函数。因此,您的变量没有设置为可以与()一起使用,这是一个会话变量,可以与下一个重定向请求一起使用

return redirect('cart')->with('index', $index);

谢谢这很有道理,而且效果很好:-)很高兴帮助@DaveChambers:)