Support the ongoing development of Laravel.io →
Requests Views
Last updated 2 years ago.
0

Do you need this data on server side or client side only? If the latter one, how about using HTML5 Local Storage?

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Trying to read out the Session in my blade file doesn't work for some reason. Any ideas?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

2akurate 2akurate Joined 13 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.