Up to 35% OFF 🎉
Go VIP and download everything FREE!
Ends in 4h 10m 55s

Storage::disk($disk)->put($path, $content); return PDFDocument::create([ 'user_id' => $userId, 'title' => $title, 'filename' => $filename, 'disk' => $disk, 'path' => $path, 'size' => Storage::disk($disk)->size($path), 'mime_type' => 'application/pdf', 'metadata' => $metadata, ]); }

Schema::create('pdf_documents', function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->constrained(); $table->string('title'); $table->string('filename'); $table->string('disk')->default('local'); // local, s3, google_drive, dropbox $table->string('path'); $table->string('mime_type')->default('application/pdf'); $table->unsignedBigInteger('size')->nullable(); // in bytes $table->json('metadata')->nullable(); // Store custom data like invoice_id, report_date $table->string('share_token')->unique()->nullable(); // for public access $table->timestamp('expires_at')->nullable(); // for expiring links $table->timestamps(); $table->softDeletes(); // enable trash feature $table->index(['user_id', 'created_at']); $table->index('share_token'); });

// Generate a unique filename $fileName = 'invoice_' . $order->invoice_number . '.pdf'; $filePath = 'pdfs/' . $fileName; // Store locally temporarily \Storage::disk('local')->put($filePath, $pdf->output()); // Now pass to your PDFDrive manager $pdfRecord = PDFDrive::store($filePath, $order); return redirect()->route('pdf.show', $pdfRecord->id); } } To manage PDFs like a drive, you need a robust table. Here's a migration example:

'disks' => [ 'google_drive' => [ 'driver' => 'google', 'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'), 'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'), 'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'), 'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'), // root folder for PDFs ], ], Then simply use Storage::disk('google_drive') in your PDFDrive service. composer require spatie/flysystem-dropbox Option C: Amazon S3 (Already native) 'driver' => 's3', Pro tip : Set a default disk in your .env :

return Storage::disk($pdf->disk)->response($pdf->path); }

public function destroy(PDFDocument $pdf) { $this->authorize('delete', $pdf); Storage::disk($pdf->disk)->delete($pdf->path); $pdf->delete();

composer require nao-pon/flysystem-google-drive Configure config/filesystems.php :

public function share($token) { $pdf = PDFDocument::where('share_token', $token) ->where('expires_at', '>', now()) ->firstOrFail();

Similar cases

Pdfdrive - Laravel

Storage::disk($disk)->put($path, $content); return PDFDocument::create([ 'user_id' => $userId, 'title' => $title, 'filename' => $filename, 'disk' => $disk, 'path' => $path, 'size' => Storage::disk($disk)->size($path), 'mime_type' => 'application/pdf', 'metadata' => $metadata, ]); }

Schema::create('pdf_documents', function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->constrained(); $table->string('title'); $table->string('filename'); $table->string('disk')->default('local'); // local, s3, google_drive, dropbox $table->string('path'); $table->string('mime_type')->default('application/pdf'); $table->unsignedBigInteger('size')->nullable(); // in bytes $table->json('metadata')->nullable(); // Store custom data like invoice_id, report_date $table->string('share_token')->unique()->nullable(); // for public access $table->timestamp('expires_at')->nullable(); // for expiring links $table->timestamps(); $table->softDeletes(); // enable trash feature $table->index(['user_id', 'created_at']); $table->index('share_token'); });

// Generate a unique filename $fileName = 'invoice_' . $order->invoice_number . '.pdf'; $filePath = 'pdfs/' . $fileName; // Store locally temporarily \Storage::disk('local')->put($filePath, $pdf->output()); // Now pass to your PDFDrive manager $pdfRecord = PDFDrive::store($filePath, $order); return redirect()->route('pdf.show', $pdfRecord->id); } } To manage PDFs like a drive, you need a robust table. Here's a migration example: laravel pdfdrive

'disks' => [ 'google_drive' => [ 'driver' => 'google', 'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'), 'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'), 'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'), 'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'), // root folder for PDFs ], ], Then simply use Storage::disk('google_drive') in your PDFDrive service. composer require spatie/flysystem-dropbox Option C: Amazon S3 (Already native) 'driver' => 's3', Pro tip : Set a default disk in your .env :

return Storage::disk($pdf->disk)->response($pdf->path); } // Store locally temporarily \Storage::disk('local')-&gt

public function destroy(PDFDocument $pdf) { $this->authorize('delete', $pdf); Storage::disk($pdf->disk)->delete($pdf->path); $pdf->delete();

composer require nao-pon/flysystem-google-drive Configure config/filesystems.php : [ 'google_drive' =&gt

public function share($token) { $pdf = PDFDocument::where('share_token', $token) ->where('expires_at', '>', now()) ->firstOrFail();

Best Selling Products