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

Igeruns's avatar

Session variable not available in Laravel Chart Class

Hi,

I'm trying to get session variable in class responsible for providing data to chartisan and it's null. I can't find out why?

In controller I set session variable and would like to read it in Chart class. I'am using Laravel 8 and "consoletvs/charts": "7.*",

My code is below.

// Controler and function which generates view
if ($request->has('stopDateAssets'))
        {
            $stopDateAssets = request('stopDateAssets');
            session(['stopDateAssets' => $stopDateAssets]);

        } elseif ($request->session()->has('stopDateAssets')) {
            $stopDateAssets = session('stopDateAssets');

        } else {
            $stopDateAssets = Carbon::now()->toDateString();
            session(['stopDateAssets' => $stopDateAssets]);
        }

// class TotalAssetsUSDChart extends BaseChart
$stopDateAssets = session('stopDateAssets');

Could you please explain me why session variable is null?

0 likes
2 replies
Snapey's avatar

try adding session()->save() in the controller

Igeruns's avatar

I tried but the same result.

In controller, session variable is saved and accessible but in class ConsoleTVs\Charts\BaseChart it's still null.

Could it be caused because of boot order? How to put in chart class, variable which is set in controller? In my case I need specific date to be available in chart generating class which I set in controller.

Please or to participate in this conversation.