Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maxehnert's avatar

saving localStorage session to db

Before I start, I would like to note that I am new to laravel and php.

I am using AJAX calls to localStorage to save annotations that need to be created/updated/deleted without page reloads during a users session.

However I need to save that data to a db at the end of the session, and load it in at the beginning of one.

My problem I have is trying to figure out how to bridge the gap of loading data from a db into localStorage.

I have been searching for a couple days and can't come up with a solution.

I may be approaching this problem the wrong way, so I am open to all suggestions.

0 likes
2 replies
Ozan's avatar

You can wrap you entire routes in a Route::group() and use the before key to run a specific Middleware everytime the app loads.

Route::group([
    'before' => 'beforeMiddleware',
    'after' => 'afterMiddleware',
], function()
{
    // your routes
});

Please or to participate in this conversation.