mardi 31 octobre 2017

saving into 2D session in laravel

I'm trying to convert a pure PHP code to Laravel. This code works with session extensively - here is the simplified part of the code (please ignore syntax errors):

    $_SESSION['gamedata']=[
        'game'=> 23 ,
        'n'=>0,
        'Cards'=>[],
        'Values'=>[],
    ];
    $_SESSION['gamedata']['Cards'][]= getCard();
    $_SESSION['gamedata']['Values'][]= getVal();

right now based on the laravel documentation my option is

    session(['gamedata' =>  [
        'game'=> 23 ,
        'n'=>0,
        'Cards'=>[],
        'Values'=>[],
    ]]);

    $gamedata = session('gamedata');
    $gamedata['Cards'][]= getCard();
    session(['gamedata'=>$gamedata]);

    $gamedata = session('gamedata');
    $gamedata['Values'][]= getVal();
    session(['gamedata'=>$gamedata]);

which is very stupid ... and no i cant save it one at the end of the line becuz functions also work with session so session needs to be saved before each function call

basically i want to be able to save in 2d session instantly something like

session([ ['gamedata']['Cards'][] => getCards() ]);

which right now gives me this error

Cannot use [] for reading

even this code

session([ ['gamedata']['Cards'] => getCards() ]);

gives me this error

Undefined index: Cards



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2h0j049
via IFTTT

Aucun commentaire:

Enregistrer un commentaire