doufu9145 2013-12-18 15:34 采纳率: 0%
浏览 36
已采纳

向现有会话添加密钥和值

I try to add a key and a value in a already existing session with laravel and this goes fine but the key is not as I pass with the Session function

public function selectCar() {

    $reservation['car'] = Input::get('id'); 

    if (Session::has('car')) {
        Session::forget('car');
    }

    if (Input::has('id'))
    {
        Session::push('reserveringen', $reservation['car']);
    }

    $data = Session::all();
    return Redirect::back()->with('success', 'Auto gekozen')->with('sessie', $data);

}

The output is

[reserveringen] => Array
            (
                [pickupdate] => 'date'
                [pickuptime] => 'time'
                [returndate] => 'date'
                [returntime] => 'time'
                [0] => 37
            )

But It shows 0 instead of 'car' The next thing is that if the session already contains car I want the old one to delete and be replace by the new one. Can someone give me an example of how to achieve this?

  • 写回答

1条回答 默认 最新

  • dongsheng4126335 2013-12-18 15:39
    关注

    You are not passing the array key, so this is a way to pass it:

    if (Input::has('id'))
    {
        Session::push('reserveringen', array('car' => $reservation['car']));
    }
    

    But it will push an new array to that array, not your 'car' key.

    So, you might need to do this to put your 'car' key correctly:

    $reserveringen = Session::get('reserveringen');
    
    $reserveringen['car'] = $reservation['car'];
    
    Session::put('reserveringen', $reserveringen);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!