Support the ongoing development of Laravel.io →
posted 10 years ago
Session

I'm currently attempting to extend the session facade, so instead of using Session::put('company', $company); throughout my app, I'm using Session::setCurrentCompany($company); and so on. To accomplish this, I extended \Illuminate\Session\SessionManager to add a few methods.

    public function preferenceTimeZone()
    {
        return $this->get('preferenceTimeZone', App::make('DateTimeZone', ['America/New_York']));
    }

    public function setPreferenceTimeZone(DateTimeZone $timeZone)
    {
        $this->set('preferenceTimeZone', $timeZone);
    }

With this method, I'm able to define my session variables and do Session::all(); and see every variable that has been set on the same page . Utilizing $this->get() is the exact same as calling Session::get(), or at least should be. However when I redirect the page, any variables set with my special methods are not saved, whereas those defined with Session::set() or Session::put() save just fine.

Any ideas on why this would be the case?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

bkuhl bkuhl Joined 27 Mar 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.

© 2025 Laravel.io - All rights reserved.