Is it possible to store an array as flash data in Laravel?

AntonNiklasson picture AntonNiklasson · Nov 4, 2013 · Viewed 15k times · Source

I have been looking around for a way of doing this. I know it is possible to store an array in the session with the following: Session::push('user.teams', 'developers');

Is it possible to do the same but with flash data? Something like Session::flashpush('user.teams', array('developers', 'designers')); would be great.

The usecase for me at this moment is primarily the following:

Session::flash('flash_message', $validator->messages());

Answer

Israel Ortuño picture Israel Ortuño · Nov 4, 2013

As far as I know, you can do it. I've checked this just in case:

Session::flash('test', array('test1', 'test2', 'test3'));

... After the request

dd(Session::get('test'));

// array(2) { [0]=> string(5) "test1" [1]=> string(5) "test2" [2]=> string(5) "test3" }

It works. Also you can serialize an array or object as Christopher Morrissey just commented