0

I'm kinda lost in using array session in Laravel 4.2. In the documentation, it says Session::push('user.teams', 'developers');.

I'm assuming that the user.team is the session name then the developers is the value. So can I do something like this,

Session::push('book.id','1234');
Session::push('book.name','Sample book');
Session::push('book.rating','5');

and I'll get it as $bookName= Session::get('book.name');

Am I doing this right? or should I just use individual sessions?

2 Answers 2

1

First thing you put the array you want, then you push elements to this array by using the . symbol

$user = ['name'=>'ahmed'];
Session::put('user' , $user);    // Put the array
Session::push('user.age','15');  // Push an Element
//$user = Session::get('user');  // Retrieve all the array
dd(Session::get('user.age'));    // Retrieve only one element
Sign up to request clarification or add additional context in comments.

Comments

1

Yes you are doing it right. Array of session in permitted and usable in laravel.

For more information you can have a look at laravel documentation.

http://laravel.com/docs/5.0/session

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.