Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with Laravel's dot notation when using sessions

I'm having a slight problem when trying to store and grab items from the session. I'm using an API and I am attempting to cache the results of this api into the session.

The problem is the API often returns domain names which I am trying to cache, google.com for example and then a value for that domain.

Unfortunately, when I store this using Session::put($domain, $value) and then return Session::all(), the array looks like the following...

array(
    'google' => 
        'com' => 'my_value'
)

I really need it to be...

array(
    'google.com' => 'my_value'
)

As you can see, the dot notation is destroying the integrity of the array depending.

like image 366
user1669496 Avatar asked Dec 06 '25 15:12

user1669496


1 Answers

Looking at Laravel code, you won't be able to solve it easily. Laravel uses here Arr::set method which uses dot notation to create multi dimensional array.

You should consider replacing . into for example _ so instead google.com use google_com as your session key.

like image 72
Marcin Nabiałek Avatar answered Dec 08 '25 03:12

Marcin Nabiałek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!