Do you need this data on server side or client side only? If the latter one, how about using HTML5 Local Storage?
You can use JSON.stringify(data) where data can be string, object, array or whatever
Then in controller you can use json_decode to convert the string to array
TorchSK said:
You can use JSON.stringify(data) where data can be string, object, array or whatever
Then in controller you can use json_decode to convert the string to array
This is a great idea. To send this data through to the next page, if it's not a lot of data, you could store it in a session then pass that session data through to the receiving controller method for processing.
Storing the data like this (if you were passing a data attribute) in ajax:
$('body').on('click','<element>',function(e){
e.preventDefault();
var data = $(this).data('to-store');
sessionStorage.setItem('stored_data', data);
});
I'm making an assumption on your route here, but if I'm right, then it would be like '/next/{data}' ? So, you could put this in an anchor tag 'href'
{{ Url::action('UsersController@showNext', ['data' => Session::get('stored_data')]) }}
This is untested code and off the top of my head so it may have a logical hole, but it wouldn't hurt to try.
Trying to read out the Session in my blade file doesn't work for some reason. Any ideas?
I think I may have slipped up on the syntax, instead of:
Session::get('stored_data')
You may need to store it in a variable instead.
$variable = Session::get('stored_data')
Haven't researched the reasoning behind it yet, but this syntax is what's working for me.
I save in session in js file, I stringify because its an array and you can only send string.
sessionStorage.setItem('data', JSON.stringify(wordList));
I read it out in another js file.
var wordList = JSON.parse(sessionStorage.getItem('data'));
This will have to do for now, thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community