Your PDFDrive needs a reliable engine. Laravel offers several excellent packages. Here are the top three:
Perfect for SaaS apps where users shouldn’t access each other’s PDFs:
$url = Storage::disk('pdfs')->temporaryUrlFromView( 'pdfs.contract', $user->contractData, "contracts/$user->id/agreement.pdf", now()->addDay() );
return response()->json(['download_url' => $url]);
Inside boot() method:
use Illuminate\Support\Facades\Storage; use Barryvdh\DomPDF\Facade\Pdf;
Storage::extend('pdfdrive', function ($app, $config) return new \App\Filesystems\PDFDriveDriver( $app['filesystem']->disk($config['storage_disk'] ?? 'local'), $config ); );
Here's how to expose your PDFDrive to users.
To manage PDFs like a drive, you need a robust table. Here's a migration example:
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');
);
Create a corresponding Eloquent model:
class PDFDocument extends Model use SoftDeletes;protected $fillable = ['title', 'filename', 'disk', 'path', 'size', 'metadata', 'share_token', 'expires_at']; protected $casts = ['metadata' => 'array', 'expires_at' => 'datetime']; public function user() return $this->belongsTo(User::class); public function getUrlAttribute(): string return Storage::disk($this->disk)->url($this->path); public function getTemporaryUrl($expiresInMinutes = 15): string return Storage::disk($this->disk)->temporaryUrl($this->path, now()->addMinutes($expiresInMinutes));
Підтримати нас можна через:
Приват: 5169 3351 0164 7408
PayPal - [email protected]
Стати нашим патроном за лінком ⬇
Subscribe to our newsletter
or on ours Telegram
Thank you!!
You are subscribed to our newsletter