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

Digisol's avatar

Streaming a file to Laravel Storage

I am using JPGraph to generate a graph, the hope is to then save the graph to the file system and point to it in a view. I am attempting to render that view into a PDF later (this is why I'm not generating the chart on the fly).

The problem I am having is I can't figure out how to get the Stream method in JPGraph to save to the laravel file system.

        $graph = new Graph\PieGraph(350, 250);
        $graph->title->Set("A Simple Pie Plot");
        $graph->SetBox(true);
     
        $legends = ['A (%d)','B (%d)','C (%d)','D (%d)','E (%d)',];
        $data = array(40, 21, 17, 14, 23);
        $p1   = new Plot\PiePlot($data);
        
        $p1->SetLegends($legends);

        $p1->ShowBorder();
        $p1->SetColor('black');
        $p1->SetSliceColors(array('#1E90FF', '#2E8B57', '#ADFF2F', '#DC143C', '#BA55D3'));
        $graph->legend->SetPos(0.5,0.98,'center','bottom');
        $graph->Add($p1);
        $graph->img->Stream(/* TO LARAVEL STORAGE */);

I have tried pointing directly to the path using storage_path('images\graphs\test.png'); but I get a permissions error.

0 likes
0 replies

Please or to participate in this conversation.