Search code examples
laravelfile-storage

Laravel Storage not storing created PDF files


I am facing an issue where my created PDF's are not being stored in laravel.

I have the following set in my filesystems.php under the disks tag

'completedforms' => [
        'driver' => 'local',
        'root' => storage_path('app/storage/completedforms'),
    ],

In my controller I have the following:

$pdf = PDF::loadView('report.form19',  compact('generalreport','monthlyRoll', 'nightsInMonth', 'groupfee', 'subs', 'wing','weeksinmonth', 'meetingnights', 'lastRollMap', 'month_name', 'totalmember', 'totalcadets', 'totalnco', 'totalto', 'totalofficer'));
Storage::disk('completedforms')->put('Form 19 - '.$month_name . ' ' . $lastRollMap->roll_year.'.pdf', $pdf->output());
    
return $pdf->download ('Form 19 - '.$month_name . ' ' . $lastRollMap->roll_year.'.pdf');

I have added use Illuminate\Support\Facades\Storage; to my Controller

The pdf is created and downloads no issues, however the file is not being saved in the located as difined for the disk in the filesystems.php.

I have created the folder manually to ensure it exists. I have even set the file name to test.php to remove any variables fromm the file name


Solution

  • storage_path already starts at: /storage, so change it like so:

    'root' => storage_path('/desired'),