【问题标题】:Laravel 5.1 Session not workingLaravel 5.1 会话不工作
【发布时间】:2016-05-02 15:03:49
【问题描述】:

我的控制器商店中有 Session

public function store(Request $request)
{
\Session::push('store_pos.items',$request->all());
print_r(\Session::get('store_pos.items')); // This is show array
exit;
}

public function create()
{
$items = \Session::get('store_pos.items');
print_r($items); // in this syntax not show array
}

为什么函数创建中的会话不显示? 我一直在使用session put但仍然没有出现

谢谢

【问题讨论】:

  • 你先调用什么函数? .
  • 每次调用\Session::get('store_pos.items');总是空的,因为store方法还没有被调用。
  • 你能给我样品吗?请:(
  • 我想知道你想要达到什么目的?所以也许我可以帮助你更好的方法或答案。
  • 我制作了一个交易表单,在刷新页面时表单交易中的值没有丢失

标签: php laravel session laravel-5.1


【解决方案1】:

您的控制器在“网络”中间件下吗?

任何未放置在 web 中间件组中的路由都将无法访问会话和 CSRF 保护,因此请确保将需要这些功能的所有路由放置在该组中。

【讨论】:

    【解决方案2】:

    如果您想在提交表单时出现任何错误时返回输入,您可以这样做:

    $trans = new Transaction();
    // Do all the input stuff
    
    if($trans->save()){
    // your code if the transaction successfully save
    }
    
    return back()->withInput(); // this will return back to the page with input
    
    //or if  you prefer facade
    
    return Redirect::back()->withInput();
    

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      相关资源
      最近更新 更多