Skip to content

[5.8] Extract session saving to a method#27771

Merged
taylorotwell merged 1 commit into
laravel:5.8from
jasonvarga:5.8
Mar 5, 2019
Merged

[5.8] Extract session saving to a method#27771
taylorotwell merged 1 commit into
laravel:5.8from
jasonvarga:5.8

Conversation

@jasonvarga

Copy link
Copy Markdown
Contributor

This PR simply moves the saving logic into a method so we can override without needing to override the entire handle method.

Our use case:

We have a feature in our app that lets you track how long is left in your session from a specific route.

Every request will add a last_activity timestamp to the user's session.

On one route, we want to check the last_activity timestamp without extending the session (which, normally every request would do).

Our SaveSession middleware would end up looking like this:

protected function saveSession()
{
    if (request()->route()->named('statamic.cp.session.timeout')) {
        return;
    }

    session()->put('last_activity', now()->timestamp);

    parent::saveSession();
}

@driesvints driesvints changed the title Extract session saving to a method [5.8] Extract session saving to a method Mar 4, 2019
@taylorotwell taylorotwell merged commit 1533901 into laravel:5.8 Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants