Update live data in view with Laravel 4
I would like to send data to update live in a view - what is the best way
to do that in laravel 4?
The Setup
I'm working on a Laravel 4 based project where each user can redeem a
serial key.
I've made an admin backend where I can easily paste in a list of keys, or
upload a file of them.
Let's say $key_string is the string of newline-seperated keys that I've
uploaded, and want to parse out to then upload the contained key strings
from - here is the simplified code that adds the keys:
$key_string = rtrim($key_string);
$key_string = str_replace("\n\r", "\n", $key_string);
$keys = explode( "\n", $key_string);
$count = 0;
foreach($keys as $key) {
Key::create(
array( "serial" => trim($key) )
);
$count++;
}
Since the sets of keys I upload number in the thousands, this can
sometimes take a good 30 seconds, during which time the admin panel
naturally doesn't show anything.
Now, I don't mind it taking this time. I don't need to optimize the upload
to use one query, etc, but I would like to have some actual feedback so I
know how far the upload has gone.
The Question
I would like to be able to send the contents of $count to the view every
few seconds or percent ticks, to show a progress bar for when I upload
keys.
Is there an easy way to handle this painlessly, preferably integrated in
Laravel 4? I'm assuming this would involve ajax, but can someone point me
in the right direction?
No comments:
Post a Comment